Skip to content

Commit

Permalink
Merge pull request #285 from driehle/fix/unit-tests
Browse files Browse the repository at this point in the history
Fix unit tests for 5.0.x branch
  • Loading branch information
driehle committed Jan 21, 2024
2 parents 334ee7f + 57454cf commit baddd74
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
17 changes: 17 additions & 0 deletions tests/Assets/CustomClassMetadataFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace DoctrineMongoODMModuleTest\Assets;

use Doctrine\ODM\MongoDB\Mapping\ClassMetadataFactoryInterface;
use Doctrine\Persistence\Mapping\ClassMetadata;

/**
* @method list<ClassMetadata> getAllMetadata()
* @method ClassMetadata[] getLoadedMetadata()
* @method ClassMetadata getMetadataFor($className)
*/
abstract class CustomClassMetadataFactory implements ClassMetadataFactoryInterface
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Doctrine\ODM\MongoDB\Repository\DocumentRepository;

class DefaultDocumentRepository extends DocumentRepository
class CustomDocumentRepository extends DocumentRepository
{
public function isCustomDefaultDocumentRepository(): bool
{
Expand Down
7 changes: 4 additions & 3 deletions tests/Doctrine/ConfigurationFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
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;
use DoctrineMongoODMModuleTest\Assets\DefaultDocumentRepository as CustomDocumentRepository;
use Laminas\ServiceManager\ServiceManager;

use function assert;
Expand Down Expand Up @@ -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,
],
Expand Down Expand Up @@ -118,8 +119,8 @@ public function testCreation(): void
$this->assertSame($persistentCollectionGenerator, $config->getPersistentCollectionGenerator());

$this->assertInstanceOf($typeClassName, Type::getType($typeName));
$this->assertSame(CustomClassMetadataFactory::class, $config->getClassMetadataFactoryName());
$this->assertSame($repositoryFactory, $config->getRepositoryFactory());

$this->assertSame(CustomDocumentRepository::class, $config->getDefaultDocumentRepositoryClassName());
}
}
6 changes: 3 additions & 3 deletions tests/Doctrine/CustomDefaultRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}
}
2 changes: 1 addition & 1 deletion tests/testing.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down

0 comments on commit baddd74

Please sign in to comment.