From 247f5817fde58a3dabdc78556f0807221dbdb8d1 Mon Sep 17 00:00:00 2001 From: Dennis Riehle Date: Sun, 21 Jan 2024 16:57:39 +0100 Subject: [PATCH 1/2] added test cases for config instantiation --- ...tDocumentRepository.php => CustomDocumentRepository.php} | 2 +- tests/Doctrine/ConfigurationFactoryTest.php | 4 ++-- tests/Doctrine/CustomDefaultRepositoryTest.php | 6 +++--- tests/testing.config.php | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) rename tests/Assets/{DefaultDocumentRepository.php => CustomDocumentRepository.php} (79%) diff --git a/tests/Assets/DefaultDocumentRepository.php b/tests/Assets/CustomDocumentRepository.php similarity index 79% rename from tests/Assets/DefaultDocumentRepository.php rename to tests/Assets/CustomDocumentRepository.php index bd838b1..ccbf09a 100644 --- a/tests/Assets/DefaultDocumentRepository.php +++ b/tests/Assets/CustomDocumentRepository.php @@ -6,7 +6,7 @@ use Doctrine\ODM\MongoDB\Repository\DocumentRepository; -class DefaultDocumentRepository extends DocumentRepository +class CustomDocumentRepository extends DocumentRepository { public function isCustomDefaultDocumentRepository(): bool { diff --git a/tests/Doctrine/ConfigurationFactoryTest.php b/tests/Doctrine/ConfigurationFactoryTest.php index 92eb731..1f57d54 100644 --- a/tests/Doctrine/ConfigurationFactoryTest.php +++ b/tests/Doctrine/ConfigurationFactoryTest.php @@ -14,9 +14,9 @@ use Doctrine\Persistence\Mapping\Driver\MappingDriver; use DoctrineMongoODMModule\Service\ConfigurationFactory; use DoctrineMongoODMModuleTest\AbstractTest; +use DoctrineMongoODMModuleTest\Assets\CustomDocumentRepository; use DoctrineMongoODMModuleTest\Assets\CustomRepositoryFactory; use DoctrineMongoODMModuleTest\Assets\CustomType; -use DoctrineMongoODMModuleTest\Assets\DefaultDocumentRepository as CustomDocumentRepository; use Laminas\ServiceManager\ServiceManager; use function assert; @@ -118,8 +118,8 @@ public function testCreation(): void $this->assertSame($persistentCollectionGenerator, $config->getPersistentCollectionGenerator()); $this->assertInstanceOf($typeClassName, Type::getType($typeName)); + $this->assertSame('stdClass', $config->getClassMetadataFactoryName()); $this->assertSame($repositoryFactory, $config->getRepositoryFactory()); - $this->assertSame(CustomDocumentRepository::class, $config->getDefaultDocumentRepositoryClassName()); } } diff --git a/tests/Doctrine/CustomDefaultRepositoryTest.php b/tests/Doctrine/CustomDefaultRepositoryTest.php index ebace8d..5ab6e1d 100644 --- a/tests/Doctrine/CustomDefaultRepositoryTest.php +++ b/tests/Doctrine/CustomDefaultRepositoryTest.php @@ -5,7 +5,7 @@ namespace DoctrineMongoODMModuleTest\Doctrine; use DoctrineMongoODMModuleTest\AbstractTest; -use DoctrineMongoODMModuleTest\Assets\DefaultDocumentRepository; +use DoctrineMongoODMModuleTest\Assets\CustomDocumentRepository; use DoctrineMongoODMModuleTest\Assets\Document\Simple; use function assert; @@ -18,8 +18,8 @@ public function testCustomDefaultRepository(): void $repository = $documentManager->getRepository(Simple::class); - $this->assertInstanceOf(DefaultDocumentRepository::class, $repository); - assert($repository instanceof DefaultDocumentRepository); + $this->assertInstanceOf(CustomDocumentRepository::class, $repository); + assert($repository instanceof CustomDocumentRepository); $this->assertTrue($repository->isCustomDefaultDocumentRepository()); } } diff --git a/tests/testing.config.php b/tests/testing.config.php index 7ce89ff..c276c19 100644 --- a/tests/testing.config.php +++ b/tests/testing.config.php @@ -13,7 +13,7 @@ 'configuration' => [ 'odm_default' => [ 'default_db' => 'doctrineMongoODMModuleTest', - 'default_document_repository_class_name' => Assets\DefaultDocumentRepository::class, + 'default_document_repository_class_name' => Assets\CustomDocumentRepository::class, ], ], 'connection' => [ From 57454cf891071303780d89fde98a73a3fcf51db3 Mon Sep 17 00:00:00 2001 From: Dennis Riehle Date: Sun, 21 Jan 2024 17:15:33 +0100 Subject: [PATCH 2/2] added mock for class metadata --- tests/Assets/CustomClassMetadataFactory.php | 17 +++++++++++++++++ tests/Doctrine/ConfigurationFactoryTest.php | 5 +++-- 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 tests/Assets/CustomClassMetadataFactory.php diff --git a/tests/Assets/CustomClassMetadataFactory.php b/tests/Assets/CustomClassMetadataFactory.php new file mode 100644 index 0000000..40274a5 --- /dev/null +++ b/tests/Assets/CustomClassMetadataFactory.php @@ -0,0 +1,17 @@ + getAllMetadata() + * @method ClassMetadata[] getLoadedMetadata() + * @method ClassMetadata getMetadataFor($className) + */ +abstract class CustomClassMetadataFactory implements ClassMetadataFactoryInterface +{ +} diff --git a/tests/Doctrine/ConfigurationFactoryTest.php b/tests/Doctrine/ConfigurationFactoryTest.php index 1f57d54..4182688 100644 --- a/tests/Doctrine/ConfigurationFactoryTest.php +++ b/tests/Doctrine/ConfigurationFactoryTest.php @@ -14,6 +14,7 @@ use Doctrine\Persistence\Mapping\Driver\MappingDriver; use DoctrineMongoODMModule\Service\ConfigurationFactory; use DoctrineMongoODMModuleTest\AbstractTest; +use DoctrineMongoODMModuleTest\Assets\CustomClassMetadataFactory; use DoctrineMongoODMModuleTest\Assets\CustomDocumentRepository; use DoctrineMongoODMModuleTest\Assets\CustomRepositoryFactory; use DoctrineMongoODMModuleTest\Assets\CustomType; @@ -84,7 +85,7 @@ public function testCreation(): void 'types' => [ $typeName = 'foo_type' => $typeClassName = CustomType::class, ], - 'classMetadataFactoryName' => 'stdClass', + 'classMetadataFactoryName' => CustomClassMetadataFactory::class, 'repositoryFactory' => CustomRepositoryFactory::class, 'default_document_repository_class_name' => CustomDocumentRepository::class, ], @@ -118,7 +119,7 @@ public function testCreation(): void $this->assertSame($persistentCollectionGenerator, $config->getPersistentCollectionGenerator()); $this->assertInstanceOf($typeClassName, Type::getType($typeName)); - $this->assertSame('stdClass', $config->getClassMetadataFactoryName()); + $this->assertSame(CustomClassMetadataFactory::class, $config->getClassMetadataFactoryName()); $this->assertSame($repositoryFactory, $config->getRepositoryFactory()); $this->assertSame(CustomDocumentRepository::class, $config->getDefaultDocumentRepositoryClassName()); }