From dfadbb00c252060b112d855743ad8cb9c57e3fff Mon Sep 17 00:00:00 2001 From: Anton Vasiliev <1695147@gmail.com> Date: Sun, 9 Jul 2023 21:57:30 +0100 Subject: [PATCH 1/4] Add return type --- src/Mvc/Collection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mvc/Collection.php b/src/Mvc/Collection.php index f0ba6ec..eac115c 100644 --- a/src/Mvc/Collection.php +++ b/src/Mvc/Collection.php @@ -879,7 +879,7 @@ public function getCollectionManager(): ManagerInterface * @return \MongoDB\Collection * @throws Exception */ - protected function prepareCU() + protected function prepareCU(): \MongoDB\Collection { if ($this->container === null) { throw new Exception('The services related to the ODM'); From fc8f6550524a361c80cfb516268bf157f1d94986 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev <1695147@gmail.com> Date: Sun, 9 Jul 2023 21:58:33 +0100 Subject: [PATCH 2/4] Simplify condition --- src/Mvc/Collection.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Mvc/Collection.php b/src/Mvc/Collection.php index eac115c..c062b88 100644 --- a/src/Mvc/Collection.php +++ b/src/Mvc/Collection.php @@ -1015,7 +1015,7 @@ public function serialize(): string * @param string $connectionService * @return $this */ - public function setConnectionService($connectionService): self + public function setConnectionService(string $connectionService): self { $this->collectionsManager->setConnectionService($this, $connectionService); @@ -1182,7 +1182,7 @@ public static function getTypeMap($base = null): array ]; /** @noinspection NotOptimalIfConditionsInspection */ - if (class_exists($base) && is_array($base::$typeMap)) { + if (class_exists($base)) { $typeMap = array_merge($typeMap, $base::$typeMap); } From 63907c1c3fe12e4c98156e11a689957e450c6b3b Mon Sep 17 00:00:00 2001 From: Anton Vasiliev <1695147@gmail.com> Date: Sun, 9 Jul 2023 22:03:19 +0100 Subject: [PATCH 3/4] [phalcon/incubator#973] Add test cases --- src/Mvc/Collection.php | 1 - tests/integration/Collection/AggregateCest.php | 4 +++- tests/integration/Collection/FindCest.php | 3 +++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Mvc/Collection.php b/src/Mvc/Collection.php index c062b88..13e8ae5 100644 --- a/src/Mvc/Collection.php +++ b/src/Mvc/Collection.php @@ -1244,7 +1244,6 @@ public function unserialize($data): void * Gets the default collectionsManager service */ $manager = $container->getShared("collectionManager"); - if ($manager === null) { throw new Exception( "The injected service 'collectionManager' is not valid" diff --git a/tests/integration/Collection/AggregateCest.php b/tests/integration/Collection/AggregateCest.php index 5098fe9..f546bcb 100644 --- a/tests/integration/Collection/AggregateCest.php +++ b/tests/integration/Collection/AggregateCest.php @@ -19,6 +19,7 @@ use Phalcon\Incubator\MongoDB\Mvc\Collection\Exception; use Phalcon\Incubator\MongoDB\Test\Fixtures\Mvc\Collections\Robots; use Phalcon\Incubator\MongoDB\Test\Fixtures\Traits\DiTrait; +use Traversable; class AggregateCest { @@ -69,12 +70,13 @@ public function mvcCollectionAggregate(IntegrationTester $I) $robots1 = Robots::aggregate([ [ '$match' => [ - 'first_name' => 'Wall' + 'first_name' => 'Wall', ] ] ]); $I->assertInstanceOf(Cursor::class, $robots1); + $I->assertInstanceOf(Traversable::class, $robots1); foreach ($robots1 as $rb) { $I->assertIsArray($rb); diff --git a/tests/integration/Collection/FindCest.php b/tests/integration/Collection/FindCest.php index 8abec34..5684b6a 100644 --- a/tests/integration/Collection/FindCest.php +++ b/tests/integration/Collection/FindCest.php @@ -18,6 +18,7 @@ use Phalcon\Incubator\MongoDB\Mvc\Collection\Exception; use Phalcon\Incubator\MongoDB\Test\Fixtures\Mvc\Collections\Robots; use Phalcon\Incubator\MongoDB\Test\Fixtures\Traits\DiTrait; +use Traversable; class FindCest { @@ -77,7 +78,9 @@ public function mvcCollectionFind(IntegrationTester $I) } $I->assertNotEmpty($robots); + $I->assertInstanceOf(Traversable::class, $robots); $I->assertInstanceOf(Robots::class, $result[0]); + $I->assertInstanceOf(Traversable::class, $robotsE); $I->assertCount(3, $result); $I->assertCount(2, $robotsE->toArray()); } From 24dab62f36dc1c588acc7c056af53bf6b4255d69 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev <1695147@gmail.com> Date: Sun, 9 Jul 2023 22:08:15 +0100 Subject: [PATCH 4/4] Refactor 'validations' job in CI --- .github/workflows/main.yml | 22 +++++++++++++++++++--- Dockerfile | 6 ------ 2 files changed, 19 insertions(+), 9 deletions(-) delete mode 100644 Dockerfile diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 848ac9d..d5ecd14 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,12 +2,27 @@ name: Tests & Validations on: [ push ] jobs: - phpcs: + validations: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: Run PHP_CodeSniffer - run: docker run --rm -v $(pwd):/data cytopia/phpcs --standard=./phpcs.xml.dist + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + extensions: mbstring, intl, json, mongodb-1.16.0, phalcon, xdebug + tools: pecl + ini-values: apc.enable_cli=on, session.save_path=/tmp + + - run: composer install --no-interaction --no-ansi --no-progress + + - name: run psalm + if: always() + run: vendor/bin/psalm + + - name: run phpcs + run: vendor/bin/phpcs run-tests: name: PHP ${{ matrix.php-versions }} with Phalcon ${{ matrix.phalcon-versions }} @@ -27,6 +42,7 @@ jobs: phalcon-versions: [ '5.0.0', '5.0.1', '5.0.2', '5.0.3', '5.0.4', '5.0.5', '5.1.0', '5.1.1', '5.1.2', '5.1.3', '5.1.4', '5.2.0', '5.2.1', '5.2.2' ] steps: - uses: actions/checkout@v3 + - name: Setup cache environment id: cache-env uses: shivammathur/cache-extensions@v1 diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index b7464f0..0000000 --- a/Dockerfile +++ /dev/null @@ -1,6 +0,0 @@ -FROM toroia/phalcon-cli - -RUN apk update \ - && apk add --no-cache \ - -X http://dl-cdn.alpinelinux.org/alpine/edge/testing \ - php7-pecl-mongodb