From 5453417e5b6442f7a339e6240565fd5fdb6c6497 Mon Sep 17 00:00:00 2001 From: Divine <48183131+divine@users.noreply.github.com> Date: Thu, 27 Jul 2023 01:51:21 +0300 Subject: [PATCH 1/7] fix: UniqueEntity::$service is considered final --- Validator/Constraints/Unique.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Validator/Constraints/Unique.php b/Validator/Constraints/Unique.php index 5b5b6a92..441d5eaa 100644 --- a/Validator/Constraints/Unique.php +++ b/Validator/Constraints/Unique.php @@ -16,6 +16,11 @@ #[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)] class Unique extends UniqueEntity { - /** @var string */ - public $service = 'doctrine_odm.mongodb.unique'; + /** + * The validator must be defined as a service with this name. + */ + public function validatedBy(): string + { + return 'doctrine_odm.mongodb.unique'; + } } From c3ba15b79b0c3f4c0585217a67f3004f7b85a1bc Mon Sep 17 00:00:00 2001 From: Divine <48183131+divine@users.noreply.github.com> Date: Thu, 27 Jul 2023 18:55:08 +0300 Subject: [PATCH 2/7] fix: review --- Validator/Constraints/Unique.php | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/Validator/Constraints/Unique.php b/Validator/Constraints/Unique.php index 441d5eaa..ad6337f3 100644 --- a/Validator/Constraints/Unique.php +++ b/Validator/Constraints/Unique.php @@ -17,10 +17,34 @@ class Unique extends UniqueEntity { /** - * The validator must be defined as a service with this name. + * @param array|string $fields The combination of fields that must contain unique values or a set of options + * @param bool|array|string $ignoreNull The combination of fields that ignore null values */ - public function validatedBy(): string - { - return 'doctrine_odm.mongodb.unique'; + public function __construct( + $fields, + string $message = null, + string $service = null, + string $em = null, + string $entityClass = null, + string $repositoryMethod = null, + string $errorPath = null, + bool|string|array $ignoreNull = null, + array $groups = null, + $payload = null, + array $options = [] + ) { + parent::__construct( + $fields, + $message, + 'doctrine_odm.mongodb.unique', + $em, + $entityClass, + $repositoryMethod, + $errorPath, + $ignoreNull, + $groups, + $payload, + $options + ); } } From 4a8f1a48330ab9318b2dccfc62194229a095259c Mon Sep 17 00:00:00 2001 From: Divine <48183131+divine@users.noreply.github.com> Date: Fri, 28 Jul 2023 16:08:29 +0300 Subject: [PATCH 3/7] Update Validator/Constraints/Unique.php Co-authored-by: Fran Moreno --- Validator/Constraints/Unique.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Validator/Constraints/Unique.php b/Validator/Constraints/Unique.php index ad6337f3..6fffd7a0 100644 --- a/Validator/Constraints/Unique.php +++ b/Validator/Constraints/Unique.php @@ -23,7 +23,7 @@ class Unique extends UniqueEntity public function __construct( $fields, string $message = null, - string $service = null, + string $service = 'doctrine_odm.mongodb.unique', string $em = null, string $entityClass = null, string $repositoryMethod = null, @@ -36,7 +36,7 @@ public function __construct( parent::__construct( $fields, $message, - 'doctrine_odm.mongodb.unique', + $service, $em, $entityClass, $repositoryMethod, From bee93a3162f58eab763ba5bdbd9a00f3cebd9e68 Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Sat, 29 Jul 2023 09:40:38 +0200 Subject: [PATCH 4/7] Add UniqueTest --- Tests/Validator/Constraints/UniqueTest.php | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Tests/Validator/Constraints/UniqueTest.php diff --git a/Tests/Validator/Constraints/UniqueTest.php b/Tests/Validator/Constraints/UniqueTest.php new file mode 100644 index 00000000..8931700c --- /dev/null +++ b/Tests/Validator/Constraints/UniqueTest.php @@ -0,0 +1,43 @@ += 80000) { + $loader = new AnnotationLoader(); + } else { + $loader = new AnnotationLoader(new AnnotationReader()); + } + + self::assertTrue($loader->loadClassMetadata($metadata)); + + [$constraint] = $metadata->getConstraints(); + assert($constraint instanceof Unique); + self::assertSame(['email'], $constraint->fields); + self::assertSame('doctrine_odm.mongodb.unique', $constraint->validatedBy()); + } +} + +/** @Unique(fields={"email"}) */ +#[Unique(['email'])] +class UniqueDocumentDummyOne +{ + private string $email; +} From 8134a6ee81fbe7495a29fc1ce4b879d90ce75a46 Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Mon, 31 Jul 2023 08:37:59 +0200 Subject: [PATCH 5/7] Prepare tests for PHPUnit 10 (#778) * Migrate phpunit XML configuration * Use TestCase suffix for abstract test classes * Make data providers static * Mark risky test as it does not perform assertions * Rename Test.php classes --- Tests/CacheWarmer/HydratorCacheWarmerTest.php | 2 +- .../PersistentCollectionCacheWarmerTest.php | 2 +- Tests/ContainerTest.php | 4 ++-- ...hp => AbstractMongoDBExtensionTestCase.php} | 2 +- .../Compiler/CacheCompatibilityPassTest.php | 5 ++++- .../DependencyInjection/ConfigurationTest.php | 8 ++++---- .../DoctrineMongoDBExtensionTest.php | 4 ++-- .../Document/{Test.php => TestDocument.php} | 2 +- .../Document/{Test.php => TestDocument.php} | 2 +- .../Document/{Test.php => TestDocument.php} | 2 +- .../Document/{Test.php => TestDocument.php} | 2 +- .../Document/{Test.php => TestDocument.php} | 2 +- .../Document/{Test.php => TestDocument.php} | 2 +- .../XmlMongoDBExtensionTest.php | 2 +- .../YamlMongoDBExtensionTest.php | 2 +- ...iverTest.php => AbstractDriverTestCase.php} | 2 +- Tests/Mapping/Driver/XmlDriverTest.php | 2 +- phpunit.xml.dist | 18 +++++++++--------- 18 files changed, 34 insertions(+), 31 deletions(-) rename Tests/DependencyInjection/{AbstractMongoDBExtensionTest.php => AbstractMongoDBExtensionTestCase.php} (99%) rename Tests/DependencyInjection/Fixtures/Bundles/AnnotationsBundle/Document/{Test.php => TestDocument.php} (92%) rename Tests/DependencyInjection/Fixtures/Bundles/AttributesBundle/Document/{Test.php => TestDocument.php} (92%) rename Tests/DependencyInjection/Fixtures/Bundles/DocumentListenerBundle/Document/{Test.php => TestDocument.php} (92%) rename Tests/DependencyInjection/Fixtures/Bundles/NewXmlBundle/src/Document/{Test.php => TestDocument.php} (88%) rename Tests/DependencyInjection/Fixtures/Bundles/OtherXmlBundle/Document/{Test.php => TestDocument.php} (88%) rename Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/Document/{Test.php => TestDocument.php} (88%) rename Tests/Mapping/Driver/{AbstractDriverTest.php => AbstractDriverTestCase.php} (97%) diff --git a/Tests/CacheWarmer/HydratorCacheWarmerTest.php b/Tests/CacheWarmer/HydratorCacheWarmerTest.php index 9c3a0552..d9ed5389 100644 --- a/Tests/CacheWarmer/HydratorCacheWarmerTest.php +++ b/Tests/CacheWarmer/HydratorCacheWarmerTest.php @@ -69,7 +69,7 @@ public function testWarmerNotExecuted(int $autoGenerate): void } /** @return array */ - public function provideWarmerNotExecuted(): array + public static function provideWarmerNotExecuted(): array { return [ [ Configuration::AUTOGENERATE_ALWAYS ], diff --git a/Tests/CacheWarmer/PersistentCollectionCacheWarmerTest.php b/Tests/CacheWarmer/PersistentCollectionCacheWarmerTest.php index 03efcc9c..553532a6 100644 --- a/Tests/CacheWarmer/PersistentCollectionCacheWarmerTest.php +++ b/Tests/CacheWarmer/PersistentCollectionCacheWarmerTest.php @@ -61,7 +61,7 @@ public function testWarmerNotExecuted(int $autoGenerate): void $this->warmer->warmUp('meh'); } - public function provideWarmerNotExecuted(): array + public static function provideWarmerNotExecuted(): array { return [ [ Configuration::AUTOGENERATE_ALWAYS ], diff --git a/Tests/ContainerTest.php b/Tests/ContainerTest.php index 05932b2c..03fe7696 100644 --- a/Tests/ContainerTest.php +++ b/Tests/ContainerTest.php @@ -52,7 +52,7 @@ public function testLoggerConfig(bool $expected, array $config, bool $debug): vo } /** @return array */ - public function provideLoggerConfigs(): array + public static function provideLoggerConfigs(): array { $config = ['connections' => ['default' => []]]; @@ -109,7 +109,7 @@ public function testDataCollectorConfig(bool $expected, array $config, bool $deb } /** @return array */ - public function provideDataCollectorConfigs(): array + public static function provideDataCollectorConfigs(): array { $config = ['connections' => ['default' => []]]; diff --git a/Tests/DependencyInjection/AbstractMongoDBExtensionTest.php b/Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php similarity index 99% rename from Tests/DependencyInjection/AbstractMongoDBExtensionTest.php rename to Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php index d133823f..198bd8df 100644 --- a/Tests/DependencyInjection/AbstractMongoDBExtensionTest.php +++ b/Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php @@ -39,7 +39,7 @@ use function is_dir; use function reset; -abstract class AbstractMongoDBExtensionTest extends TestCase +abstract class AbstractMongoDBExtensionTestCase extends TestCase { abstract protected function loadFromFile(ContainerBuilder $container, string $file): void; diff --git a/Tests/DependencyInjection/Compiler/CacheCompatibilityPassTest.php b/Tests/DependencyInjection/Compiler/CacheCompatibilityPassTest.php index 9502b36b..8dab24d5 100644 --- a/Tests/DependencyInjection/Compiler/CacheCompatibilityPassTest.php +++ b/Tests/DependencyInjection/Compiler/CacheCompatibilityPassTest.php @@ -46,7 +46,10 @@ public function registerContainerConfiguration(LoaderInterface $loader): void self::assertTrue($kernel->isBooted()); } - /** @group legacy */ + /** + * @group legacy + * @doesNotPerformAssertions + */ public function testMetadataCacheConfigUsingNonPsr6ServiceDefinedByApplication(): void { $this->expectDeprecation('Since doctrine/mongodb-odm-bundle 4.4: Configuring doctrine/cache is deprecated. Please update the cache service "custom_cache_service" to use a PSR-6 cache.'); diff --git a/Tests/DependencyInjection/ConfigurationTest.php b/Tests/DependencyInjection/ConfigurationTest.php index 140a6659..d76e0605 100644 --- a/Tests/DependencyInjection/ConfigurationTest.php +++ b/Tests/DependencyInjection/ConfigurationTest.php @@ -217,7 +217,7 @@ public function testFullConfiguration(array $config): void } /** @return array */ - public function provideFullConfiguration(): array + public static function provideFullConfiguration(): array { $yaml = Yaml::parse(file_get_contents(__DIR__ . '/Fixtures/config/yml/full.yml')); $yaml = $yaml['doctrine_mongodb']; @@ -249,7 +249,7 @@ public function testMergeOptions(array $configs, array $expected): void } /** @return array */ - public function provideMergeOptions(): array + public static function provideMergeOptions(): array { $cases = []; @@ -371,7 +371,7 @@ public function testNormalizeOptions(array $config, array $expected): void } /** @return array */ - public function provideNormalizeOptions(): array + public static function provideNormalizeOptions(): array { $cases = []; @@ -527,7 +527,7 @@ public function testFixtureLoaderValidation(array $config): void } /** @return array */ - public function provideExceptionConfiguration(): array + public static function provideExceptionConfiguration(): array { $yaml = Yaml::parse(file_get_contents(__DIR__ . '/Fixtures/config/yml/exception.yml')); $yaml = $yaml['doctrine_mongodb']; diff --git a/Tests/DependencyInjection/DoctrineMongoDBExtensionTest.php b/Tests/DependencyInjection/DoctrineMongoDBExtensionTest.php index ddb2d0bc..fae11e35 100644 --- a/Tests/DependencyInjection/DoctrineMongoDBExtensionTest.php +++ b/Tests/DependencyInjection/DoctrineMongoDBExtensionTest.php @@ -139,7 +139,7 @@ private function getContainer($bundles = 'OtherXmlBundle'): ContainerBuilder ])); } - public function parameterProvider(): array + public static function parameterProvider(): array { return [ ['proxy_namespace', 'proxy_namespace', 'foo'], @@ -147,7 +147,7 @@ public function parameterProvider(): array ]; } - public function getAutomappingConfigurations(): array + public static function getAutomappingConfigurations(): array { return [ [ diff --git a/Tests/DependencyInjection/Fixtures/Bundles/AnnotationsBundle/Document/Test.php b/Tests/DependencyInjection/Fixtures/Bundles/AnnotationsBundle/Document/TestDocument.php similarity index 92% rename from Tests/DependencyInjection/Fixtures/Bundles/AnnotationsBundle/Document/Test.php rename to Tests/DependencyInjection/Fixtures/Bundles/AnnotationsBundle/Document/TestDocument.php index b7f4c0ea..e4de2159 100644 --- a/Tests/DependencyInjection/Fixtures/Bundles/AnnotationsBundle/Document/Test.php +++ b/Tests/DependencyInjection/Fixtures/Bundles/AnnotationsBundle/Document/TestDocument.php @@ -7,6 +7,6 @@ use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB; /** @MongoDB\Document */ -class Test +class TestDocument { } diff --git a/Tests/DependencyInjection/Fixtures/Bundles/AttributesBundle/Document/Test.php b/Tests/DependencyInjection/Fixtures/Bundles/AttributesBundle/Document/TestDocument.php similarity index 92% rename from Tests/DependencyInjection/Fixtures/Bundles/AttributesBundle/Document/Test.php rename to Tests/DependencyInjection/Fixtures/Bundles/AttributesBundle/Document/TestDocument.php index 4cbbb457..a7e45eb7 100644 --- a/Tests/DependencyInjection/Fixtures/Bundles/AttributesBundle/Document/Test.php +++ b/Tests/DependencyInjection/Fixtures/Bundles/AttributesBundle/Document/TestDocument.php @@ -7,6 +7,6 @@ use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB; #[MongoDB\Document] -class Test +class TestDocument { } diff --git a/Tests/DependencyInjection/Fixtures/Bundles/DocumentListenerBundle/Document/Test.php b/Tests/DependencyInjection/Fixtures/Bundles/DocumentListenerBundle/Document/TestDocument.php similarity index 92% rename from Tests/DependencyInjection/Fixtures/Bundles/DocumentListenerBundle/Document/Test.php rename to Tests/DependencyInjection/Fixtures/Bundles/DocumentListenerBundle/Document/TestDocument.php index e0f67ecc..4ce0b362 100644 --- a/Tests/DependencyInjection/Fixtures/Bundles/DocumentListenerBundle/Document/Test.php +++ b/Tests/DependencyInjection/Fixtures/Bundles/DocumentListenerBundle/Document/TestDocument.php @@ -7,6 +7,6 @@ use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB; #[MongoDB\Document] -class Test +class TestDocument { } diff --git a/Tests/DependencyInjection/Fixtures/Bundles/NewXmlBundle/src/Document/Test.php b/Tests/DependencyInjection/Fixtures/Bundles/NewXmlBundle/src/Document/TestDocument.php similarity index 88% rename from Tests/DependencyInjection/Fixtures/Bundles/NewXmlBundle/src/Document/Test.php rename to Tests/DependencyInjection/Fixtures/Bundles/NewXmlBundle/src/Document/TestDocument.php index be6c4b9f..1ffbf8a8 100644 --- a/Tests/DependencyInjection/Fixtures/Bundles/NewXmlBundle/src/Document/Test.php +++ b/Tests/DependencyInjection/Fixtures/Bundles/NewXmlBundle/src/Document/TestDocument.php @@ -4,6 +4,6 @@ namespace Doctrine\Bundle\MongoDBBundle\Tests\DependencyInjection\Fixtures\Bundles\NewXmlBundle\Document; -class Test +class TestDocument { } diff --git a/Tests/DependencyInjection/Fixtures/Bundles/OtherXmlBundle/Document/Test.php b/Tests/DependencyInjection/Fixtures/Bundles/OtherXmlBundle/Document/TestDocument.php similarity index 88% rename from Tests/DependencyInjection/Fixtures/Bundles/OtherXmlBundle/Document/Test.php rename to Tests/DependencyInjection/Fixtures/Bundles/OtherXmlBundle/Document/TestDocument.php index bd67e27e..46d18c16 100644 --- a/Tests/DependencyInjection/Fixtures/Bundles/OtherXmlBundle/Document/Test.php +++ b/Tests/DependencyInjection/Fixtures/Bundles/OtherXmlBundle/Document/TestDocument.php @@ -4,6 +4,6 @@ namespace Doctrine\Bundle\MongoDBBundle\Tests\DependencyInjection\Fixtures\Bundles\OtherXmlBundle\Document; -class Test +class TestDocument { } diff --git a/Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/Document/Test.php b/Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/Document/TestDocument.php similarity index 88% rename from Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/Document/Test.php rename to Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/Document/TestDocument.php index a1e6a695..8e200b8c 100644 --- a/Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/Document/Test.php +++ b/Tests/DependencyInjection/Fixtures/Bundles/XmlBundle/Document/TestDocument.php @@ -4,6 +4,6 @@ namespace Doctrine\Bundle\MongoDBBundle\Tests\DependencyInjection\Fixtures\Bundles\XmlBundle\Document; -class Test +class TestDocument { } diff --git a/Tests/DependencyInjection/XmlMongoDBExtensionTest.php b/Tests/DependencyInjection/XmlMongoDBExtensionTest.php index 204c0867..8defc06c 100644 --- a/Tests/DependencyInjection/XmlMongoDBExtensionTest.php +++ b/Tests/DependencyInjection/XmlMongoDBExtensionTest.php @@ -8,7 +8,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; -class XmlMongoDBExtensionTest extends AbstractMongoDBExtensionTest +class XmlMongoDBExtensionTest extends AbstractMongoDBExtensionTestCase { protected function loadFromFile(ContainerBuilder $container, string $file): void { diff --git a/Tests/DependencyInjection/YamlMongoDBExtensionTest.php b/Tests/DependencyInjection/YamlMongoDBExtensionTest.php index 512d2548..ac990a7f 100644 --- a/Tests/DependencyInjection/YamlMongoDBExtensionTest.php +++ b/Tests/DependencyInjection/YamlMongoDBExtensionTest.php @@ -8,7 +8,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; -class YamlMongoDBExtensionTest extends AbstractMongoDBExtensionTest +class YamlMongoDBExtensionTest extends AbstractMongoDBExtensionTestCase { protected function loadFromFile(ContainerBuilder $container, string $file): void { diff --git a/Tests/Mapping/Driver/AbstractDriverTest.php b/Tests/Mapping/Driver/AbstractDriverTestCase.php similarity index 97% rename from Tests/Mapping/Driver/AbstractDriverTest.php rename to Tests/Mapping/Driver/AbstractDriverTestCase.php index 4978de4c..ed727379 100644 --- a/Tests/Mapping/Driver/AbstractDriverTest.php +++ b/Tests/Mapping/Driver/AbstractDriverTestCase.php @@ -10,7 +10,7 @@ use PHPUnit\Framework\TestCase; use ReflectionProperty; -abstract class AbstractDriverTest extends TestCase +abstract class AbstractDriverTestCase extends TestCase { public function testFindMappingFile(): void { diff --git a/Tests/Mapping/Driver/XmlDriverTest.php b/Tests/Mapping/Driver/XmlDriverTest.php index 0b69baeb..6ef03900 100644 --- a/Tests/Mapping/Driver/XmlDriverTest.php +++ b/Tests/Mapping/Driver/XmlDriverTest.php @@ -6,7 +6,7 @@ use Doctrine\Bundle\MongoDBBundle\Mapping\Driver\XmlDriver; -class XmlDriverTest extends AbstractDriverTest +class XmlDriverTest extends AbstractDriverTestCase { protected function getFileExtension(): string { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index ca20905b..4e4480da 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -26,16 +26,16 @@ - - + + ./ - - ./Resources - ./Tests - ./vendor - - - + + + ./Resources + ./Tests + ./vendor + + From 377f4e265a19dcef605fdfa2c1d68eb6e1a37e42 Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Mon, 31 Jul 2023 08:45:45 +0200 Subject: [PATCH 6/7] Fix phpdoc return type --- Command/TailCursorDoctrineODMCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Command/TailCursorDoctrineODMCommand.php b/Command/TailCursorDoctrineODMCommand.php index 84d7af05..4e37cdc5 100644 --- a/Command/TailCursorDoctrineODMCommand.php +++ b/Command/TailCursorDoctrineODMCommand.php @@ -108,7 +108,7 @@ protected function execute(InputInterface $input, OutputInterface $output) return 0; } - /** @return ContainerInterface */ + /** @return ContainerInterface|null */ protected function getContainer() { return $this->container; From 3320f0646504f2a07d615b07bfb127dc0e4efaf8 Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Sun, 6 Aug 2023 16:35:01 +0200 Subject: [PATCH 7/7] Fix CS --- Validator/Constraints/Unique.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Validator/Constraints/Unique.php b/Validator/Constraints/Unique.php index 6fffd7a0..81fa0ad6 100644 --- a/Validator/Constraints/Unique.php +++ b/Validator/Constraints/Unique.php @@ -17,19 +17,20 @@ class Unique extends UniqueEntity { /** - * @param array|string $fields The combination of fields that must contain unique values or a set of options - * @param bool|array|string $ignoreNull The combination of fields that ignore null values + * @param string[]|string $fields The combination of fields that must contain unique values or a set of options + * @param bool|string[]|string $ignoreNull The combination of fields that ignore null values + * @param mixed $payload */ public function __construct( $fields, - string $message = null, + ?string $message = null, string $service = 'doctrine_odm.mongodb.unique', - string $em = null, - string $entityClass = null, - string $repositoryMethod = null, - string $errorPath = null, - bool|string|array $ignoreNull = null, - array $groups = null, + ?string $em = null, + ?string $entityClass = null, + ?string $repositoryMethod = null, + ?string $errorPath = null, + $ignoreNull = null, + ?array $groups = null, $payload = null, array $options = [] ) { @@ -44,7 +45,7 @@ public function __construct( $ignoreNull, $groups, $payload, - $options + $options, ); } }