From 7e8354556348ed1663d18190bd8de9f3e914c636 Mon Sep 17 00:00:00 2001 From: Alan Poulain Date: Mon, 1 Mar 2021 10:26:38 +0100 Subject: [PATCH 1/5] Add back PHPUnit tests with MongoDB --- .gitattributes | 1 - .github/workflows/ci.yml | 6 +++--- phpunit.xml.dist | 2 +- phpunit_mongodb.xml | 41 ---------------------------------------- 4 files changed, 4 insertions(+), 46 deletions(-) delete mode 100644 phpunit_mongodb.xml diff --git a/.gitattributes b/.gitattributes index 0939daedba5..1bc7f690e59 100644 --- a/.gitattributes +++ b/.gitattributes @@ -8,7 +8,6 @@ /features export-ignore /phpstan.neon.dist export-ignore /phpunit.xml.dist export-ignore -/phpunit_mongodb.xml export-ignore /tests export-ignore /update-js.sh export-ignore /yarn.lock export-ignore diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index faccaa57ed5..69b6c5b4a1f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -485,7 +485,7 @@ jobs: run: vendor/bin/behat --out=std --format=progress --profile=default --no-interaction mongodb: - name: Behat (PHP ${{ matrix.php }}) (MongoDB) + name: PHPUnit + Behat (PHP ${{ matrix.php }}) (MongoDB) runs-on: ubuntu-latest timeout-minutes: 20 strategy: @@ -529,8 +529,8 @@ jobs: run: vendor/bin/simple-phpunit --version - name: Clear test app cache run: tests/Fixtures/app/console cache:clear --ansi - - name: Run PHPUnit - run: vendor/bin/simple-phpunit + - name: Run PHPUnit tests + run: vendor/bin/simple-phpunit --group mongodb - name: Run Behat tests run: vendor/bin/behat -vv --out=std --format=progress --profile=mongodb --no-interaction diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 4518373e404..7b52597293e 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -16,7 +16,7 @@ - + diff --git a/phpunit_mongodb.xml b/phpunit_mongodb.xml deleted file mode 100644 index 0ef9e7e4d5b..00000000000 --- a/phpunit_mongodb.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - - - - - - tests - - - - - - . - - features - tests - vendor - src/Bridge/NelmioApiDoc - src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php - - - - - - - - From 4e973469898226a07b6309d6e5ad2cf0941e02c5 Mon Sep 17 00:00:00 2001 From: Alan Poulain Date: Mon, 1 Mar 2021 15:28:16 +0100 Subject: [PATCH 2/5] fix: unit tests for MongoDB --- .../MongoDbOdm/Filter/SearchFilterTest.php | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/tests/Bridge/Doctrine/MongoDbOdm/Filter/SearchFilterTest.php b/tests/Bridge/Doctrine/MongoDbOdm/Filter/SearchFilterTest.php index 0f1f163cc6c..b090f818409 100644 --- a/tests/Bridge/Doctrine/MongoDbOdm/Filter/SearchFilterTest.php +++ b/tests/Bridge/Doctrine/MongoDbOdm/Filter/SearchFilterTest.php @@ -395,6 +395,36 @@ public function provideApplyTestData(): array ], $filterFactory, ], + 'partial (multiple values)' => [ + [ + [ + '$match' => [ + 'name' => [ + '$in' => [ + new Regex('CaSE'), + new Regex('SENSitive'), + ], + ], + ], + ], + ], + $filterFactory, + ], + 'partial (multiple values; case insensitive)' => [ + [ + [ + '$match' => [ + 'name' => [ + '$in' => [ + new Regex('CaSE', 'i'), + new Regex('inSENSitive', 'i'), + ], + ], + ], + ], + ], + $filterFactory, + ], 'start' => [ [ [ @@ -423,6 +453,36 @@ public function provideApplyTestData(): array ], $filterFactory, ], + 'start (multiple values)' => [ + [ + [ + '$match' => [ + 'name' => [ + '$in' => [ + new Regex('^CaSE'), + new Regex('^SENSitive'), + ], + ], + ], + ], + ], + $filterFactory, + ], + 'start (multiple values; case insensitive)' => [ + [ + [ + '$match' => [ + 'name' => [ + '$in' => [ + new Regex('^CaSE', 'i'), + new Regex('^inSENSitive', 'i'), + ], + ], + ], + ], + ], + $filterFactory, + ], 'end' => [ [ [ @@ -451,6 +511,36 @@ public function provideApplyTestData(): array ], $filterFactory, ], + 'end (multiple values)' => [ + [ + [ + '$match' => [ + 'name' => [ + '$in' => [ + new Regex('CaSE$'), + new Regex('SENSitive$'), + ], + ], + ], + ], + ], + $filterFactory, + ], + 'end (multiple values; case insensitive)' => [ + [ + [ + '$match' => [ + 'name' => [ + '$in' => [ + new Regex('CaSE$', 'i'), + new Regex('inSENSitive$', 'i'), + ], + ], + ], + ], + ], + $filterFactory, + ], 'word_start' => [ [ [ @@ -479,6 +569,36 @@ public function provideApplyTestData(): array ], $filterFactory, ], + 'word_start (multiple values)' => [ + [ + [ + '$match' => [ + 'name' => [ + '$in' => [ + new Regex('(^CaSE.*|.*\sCaSE.*)'), + new Regex('(^SENSitive.*|.*\sSENSitive.*)'), + ], + ], + ], + ], + ], + $filterFactory, + ], + 'word_start (multiple values; case insensitive)' => [ + [ + [ + '$match' => [ + 'name' => [ + '$in' => [ + new Regex('(^CaSE.*|.*\sCaSE.*)', 'i'), + new Regex('(^inSENSitive.*|.*\sinSENSitive.*)', 'i'), + ], + ], + ], + ], + ], + $filterFactory, + ], 'invalid value for relation' => [ [], $filterFactory, From 9152056f26292b0e09a37c2ba55a63c56a9275ad Mon Sep 17 00:00:00 2001 From: Alan Poulain Date: Mon, 1 Mar 2021 15:44:54 +0100 Subject: [PATCH 3/5] fix: direct deprecations --- .../MongoDbOdm/SubresourceDataProviderTest.php | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/tests/Bridge/Doctrine/MongoDbOdm/SubresourceDataProviderTest.php b/tests/Bridge/Doctrine/MongoDbOdm/SubresourceDataProviderTest.php index 0130565ffcc..879a630431c 100644 --- a/tests/Bridge/Doctrine/MongoDbOdm/SubresourceDataProviderTest.php +++ b/tests/Bridge/Doctrine/MongoDbOdm/SubresourceDataProviderTest.php @@ -167,7 +167,7 @@ public function testGetSubresource() $dataProvider = new SubresourceDataProvider($managerRegistryProphecy->reveal(), $this->resourceMetadataFactoryProphecy->reveal(), $propertyNameCollectionFactory, $propertyMetadataFactory); - $context = ['property' => 'relatedDummies', 'identifiers' => [['id', Dummy::class]], 'collection' => true, IdentifierConverterInterface::HAS_IDENTIFIER_CONVERTER => true]; + $context = ['property' => 'relatedDummies', 'identifiers' => ['id' => [Dummy::class, 'id']], 'collection' => true, IdentifierConverterInterface::HAS_IDENTIFIER_CONVERTER => true]; $this->assertEquals([], $dataProvider->getSubresource(RelatedDummy::class, ['id' => ['id' => 1]], $context)); } @@ -256,7 +256,7 @@ public function testGetSubSubresourceItem() $dataProvider = new SubresourceDataProvider($managerRegistryProphecy->reveal(), $this->resourceMetadataFactoryProphecy->reveal(), $propertyNameCollectionFactory, $propertyMetadataFactory); - $context = ['property' => 'thirdLevel', 'identifiers' => [['id', Dummy::class], ['relatedDummies', RelatedDummy::class]], 'collection' => false, IdentifierConverterInterface::HAS_IDENTIFIER_CONVERTER => true]; + $context = ['property' => 'thirdLevel', 'identifiers' => ['id' => [Dummy::class, 'id'], 'relatedDummies' => [RelatedDummy::class, 'id']], 'collection' => false, IdentifierConverterInterface::HAS_IDENTIFIER_CONVERTER => true]; $this->assertEquals($result, $dataProvider->getSubresource(ThirdLevel::class, ['id' => ['id' => 1], 'relatedDummies' => ['id' => 1]], $context)); } @@ -353,7 +353,7 @@ public function testGetSubSubresourceItemWithExecuteOptions() $dataProvider = new SubresourceDataProvider($managerRegistryProphecy->reveal(), $this->resourceMetadataFactoryProphecy->reveal(), $propertyNameCollectionFactory, $propertyMetadataFactory); - $context = ['property' => 'thirdLevel', 'identifiers' => [['id', Dummy::class], ['relatedDummies', RelatedDummy::class]], 'collection' => false, IdentifierConverterInterface::HAS_IDENTIFIER_CONVERTER => true]; + $context = ['property' => 'thirdLevel', 'identifiers' => ['id' => [Dummy::class, 'id'], 'relatedDummies' => [RelatedDummy::class, 'id']], 'collection' => false, IdentifierConverterInterface::HAS_IDENTIFIER_CONVERTER => true]; $this->assertEquals($result, $dataProvider->getSubresource(ThirdLevel::class, ['id' => ['id' => 1], 'relatedDummies' => ['id' => 1]], $context, 'third_level_operation_name')); } @@ -405,7 +405,7 @@ public function testGetSubresourceOneToOneOwningRelation() $dataProvider = new SubresourceDataProvider($managerRegistryProphecy->reveal(), $this->resourceMetadataFactoryProphecy->reveal(), $propertyNameCollectionFactory, $propertyMetadataFactory); - $context = ['property' => 'ownedDummy', 'identifiers' => [['id', Dummy::class]], 'collection' => false, IdentifierConverterInterface::HAS_IDENTIFIER_CONVERTER => true]; + $context = ['property' => 'ownedDummy', 'identifiers' => ['id' => [Dummy::class, 'id']], 'collection' => false, IdentifierConverterInterface::HAS_IDENTIFIER_CONVERTER => true]; $this->assertEquals($result, $dataProvider->getSubresource(RelatedOwningDummy::class, ['id' => ['id' => 1]], $context)); } @@ -458,7 +458,7 @@ public function testAggregationResultExtension() $dataProvider = new SubresourceDataProvider($managerRegistryProphecy->reveal(), $this->resourceMetadataFactoryProphecy->reveal(), $propertyNameCollectionFactory, $propertyMetadataFactory, [$extensionProphecy->reveal()]); - $context = ['property' => 'relatedDummies', 'identifiers' => [['id', Dummy::class]], 'collection' => true, IdentifierConverterInterface::HAS_IDENTIFIER_CONVERTER => true]; + $context = ['property' => 'relatedDummies', 'identifiers' => ['id' => [Dummy::class, 'id']], 'collection' => true, IdentifierConverterInterface::HAS_IDENTIFIER_CONVERTER => true]; $this->assertEquals([], $dataProvider->getSubresource(RelatedDummy::class, ['id' => ['id' => 1]], $context)); } @@ -504,11 +504,6 @@ public function testGetSubresourceCollectionItem() $rAggregationBuilder = $this->prophesize(Builder::class); - $rMatch = $this->prophesize(AggregationMatch::class); - $rMatch->equals(2)->shouldBeCalled(); - $rMatch->field('id')->shouldBeCalled()->willReturn($rMatch); - $rAggregationBuilder->match()->shouldBeCalled()->willReturn($rMatch->reveal()); - $rClassMetadataProphecy = $this->prophesize(ClassMetadata::class); $rClassMetadataProphecy->hasAssociation('id')->shouldBeCalled()->willReturn(false); $rClassMetadataProphecy->isIdentifier('id')->shouldBeCalled()->willReturn(true); @@ -539,7 +534,7 @@ public function testGetSubresourceCollectionItem() $dataProvider = new SubresourceDataProvider($managerRegistryProphecy->reveal(), $this->resourceMetadataFactoryProphecy->reveal(), $propertyNameCollectionFactory, $propertyMetadataFactory); - $context = ['property' => 'id', 'identifiers' => [['id', Dummy::class, true], ['relatedDummies', RelatedDummy::class, true]], 'collection' => false, IdentifierConverterInterface::HAS_IDENTIFIER_CONVERTER => true]; + $context = ['property' => 'id', 'identifiers' => ['id' => [Dummy::class, 'id', true], [RelatedDummy::class, 'relatedDummies', true]], 'collection' => false, IdentifierConverterInterface::HAS_IDENTIFIER_CONVERTER => true]; $this->assertEquals($result, $dataProvider->getSubresource(RelatedDummy::class, ['id' => ['id' => 1], 'relatedDummies' => ['id' => 2]], $context)); } From c0410e4415bef8c53d456740fb60542962fc3b23 Mon Sep 17 00:00:00 2001 From: Alan Poulain Date: Mon, 1 Mar 2021 15:54:25 +0100 Subject: [PATCH 4/5] fix: indirect deprecations --- .../MongoDbOdm/PropertyInfo/DoctrineExtractorTest.php | 4 ---- .../MongoDbOdm/PropertyInfo/Fixtures/DoctrineDummy.php | 10 ---------- .../PropertyInfo/Fixtures/DoctrineGeneratedValue.php | 2 +- 3 files changed, 1 insertion(+), 15 deletions(-) diff --git a/tests/Bridge/Doctrine/MongoDbOdm/PropertyInfo/DoctrineExtractorTest.php b/tests/Bridge/Doctrine/MongoDbOdm/PropertyInfo/DoctrineExtractorTest.php index 36505c4dc9c..20b864155ea 100644 --- a/tests/Bridge/Doctrine/MongoDbOdm/PropertyInfo/DoctrineExtractorTest.php +++ b/tests/Bridge/Doctrine/MongoDbOdm/PropertyInfo/DoctrineExtractorTest.php @@ -54,10 +54,8 @@ public function testGetProperties(): void 'date', 'float', 'bool', - 'boolean', 'customFoo', 'int', - 'integer', 'string', 'key', 'hash', @@ -143,9 +141,7 @@ public function typesProvider(): array ['date', [new Type(Type::BUILTIN_TYPE_OBJECT, false, 'DateTime')]], ['float', [new Type(Type::BUILTIN_TYPE_FLOAT)]], ['bool', [new Type(Type::BUILTIN_TYPE_BOOL)]], - ['boolean', [new Type(Type::BUILTIN_TYPE_BOOL)]], ['int', [new Type(Type::BUILTIN_TYPE_INT)]], - ['integer', [new Type(Type::BUILTIN_TYPE_INT)]], ['string', [new Type(Type::BUILTIN_TYPE_STRING)]], ['key', [new Type(Type::BUILTIN_TYPE_INT)]], ['hash', [new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true)]], diff --git a/tests/Bridge/Doctrine/MongoDbOdm/PropertyInfo/Fixtures/DoctrineDummy.php b/tests/Bridge/Doctrine/MongoDbOdm/PropertyInfo/Fixtures/DoctrineDummy.php index 64a34ed4f65..053bf0e7357 100644 --- a/tests/Bridge/Doctrine/MongoDbOdm/PropertyInfo/Fixtures/DoctrineDummy.php +++ b/tests/Bridge/Doctrine/MongoDbOdm/PropertyInfo/Fixtures/DoctrineDummy.php @@ -101,11 +101,6 @@ class DoctrineDummy */ private $bool; - /** - * @Field(type="boolean") - */ - private $boolean; - /** * @Field(type="custom_foo") */ @@ -116,11 +111,6 @@ class DoctrineDummy */ private $int; - /** - * @Field(type="integer") - */ - private $integer; - /** * @Field(type="string") */ diff --git a/tests/Bridge/Doctrine/MongoDbOdm/PropertyInfo/Fixtures/DoctrineGeneratedValue.php b/tests/Bridge/Doctrine/MongoDbOdm/PropertyInfo/Fixtures/DoctrineGeneratedValue.php index 46ece808957..e286195a2b3 100644 --- a/tests/Bridge/Doctrine/MongoDbOdm/PropertyInfo/Fixtures/DoctrineGeneratedValue.php +++ b/tests/Bridge/Doctrine/MongoDbOdm/PropertyInfo/Fixtures/DoctrineGeneratedValue.php @@ -26,7 +26,7 @@ class DoctrineGeneratedValue { /** - * @Id(strategy="INCREMENT", type="integer") + * @Id(strategy="INCREMENT", type="int") */ public $id; From 9cef7cc636863be493a40226a5fc68a0749bf678 Mon Sep 17 00:00:00 2001 From: Alan Poulain Date: Mon, 1 Mar 2021 16:10:35 +0100 Subject: [PATCH 5/5] ci: do not run phpunit tests with elasticsearch --- .github/workflows/ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 69b6c5b4a1f..3d6fa355767 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -585,8 +585,6 @@ jobs: run: vendor/bin/simple-phpunit --version - name: Clear test app cache run: tests/Fixtures/app/console cache:clear --ansi - - name: Run PHPUnit tests - run: vendor/bin/simple-phpunit - name: Run Behat tests run: vendor/bin/behat --out=std --format=progress --profile=elasticsearch --no-interaction