Skip to content

Commit

Permalink
Merge 63affda into 232aa9d
Browse files Browse the repository at this point in the history
  • Loading branch information
TomHAnderson committed Apr 30, 2020
2 parents 232aa9d + 63affda commit 84ff4db
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 8 deletions.
5 changes: 4 additions & 1 deletion config/module.doctrine-mongo-odm.local.php.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
use Doctrine\ODM\MongoDB\Configuration;
use Doctrine\ODM\MongoDB\Repository\DocumentRepository as DefaultDocumentRepository;

return array(
'doctrine' => array(
Expand Down Expand Up @@ -40,7 +41,9 @@ return array(
//
// 'filters' => array(), // array('filterName' => 'BSON\Filter\Class'),
//
// 'logger' => null // 'DoctrineMongoODMModule\Logging\DebugStack'
// 'logger' => null // 'DoctrineMongoODMModule\Logging\DebugStack',
//
// 'default_document_repository_class_name' => DefaultDocumentRepository::class,
)
),

Expand Down
16 changes: 16 additions & 0 deletions src/DoctrineMongoODMModule/Options/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace DoctrineMongoODMModule\Options;

use Doctrine\Common\Proxy\AbstractProxyFactory;
use Doctrine\ODM\MongoDB\Repository\DocumentRepository as DefaultDocumentRepository;
use DoctrineMongoODMModule\Logging\Logger;
use Laminas\Stdlib\AbstractOptions;
use function is_bool;
Expand Down Expand Up @@ -125,6 +126,9 @@ class Configuration extends AbstractOptions
/** @var string */
protected $repositoryFactory;

/** @var string */
protected $defaultDocumentRepositoryClassName = DefaultDocumentRepository::class;

/**
* Number of times to attempt to connect if an exception is encountered
*
Expand Down Expand Up @@ -471,4 +475,16 @@ public function setRepositoryFactory(?string $repositoryFactory) : Configuration

return $this;
}

public function getDefaultDocumentRepositoryClassName() : string
{
return $this->defaultDocumentRepositoryClassName;
}

public function setDefaultDocumentRepositoryClassName(string $defaultDocumentRepositoryClassName) : self
{
$this->defaultDocumentRepositoryClassName = $defaultDocumentRepositoryClassName;

return $this;
}
}
5 changes: 5 additions & 0 deletions src/DoctrineMongoODMModule/Service/ConfigurationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ public function __invoke(ContainerInterface $container, $requestedName, ?array $
}
}

$className = $options->getDefaultDocumentRepositoryClassName();
if ($className) {
$config->setDefaultDocumentRepositoryClassName($className);
}

return $config;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ public function createService(ServiceLocatorInterface $container)
return $this($container, MongoLoggerCollector::class);
}

/**
* {@inheritDoc}
*/
public function getOptionsClass() : string
{
return Options\MongoLoggerCollector::class;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php declare(strict_types=1);

namespace DoctrineMongoODMModuleTest\Assets;

use Doctrine\ODM\MongoDB\Repository\DocumentRepository;

class DefaultDocumentRepository extends DocumentRepository
{
public function isCustomDefaultDocumentRepository()
{
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use DoctrineMongoODMModuleTest\AbstractTest;
use DoctrineMongoODMModuleTest\Assets\CustomRepositoryFactory;
use DoctrineMongoODMModuleTest\Assets\CustomType;
use DoctrineMongoODMModuleTest\Assets\DefaultDocumentRepository as CustomDocumentRepository;
use Laminas\ServiceManager\ServiceManager;
use function assert;
use function is_callable;
Expand All @@ -39,7 +40,6 @@ public function testRetryQueryValueIsSetFromConfigurationOptions() : void
public function testCreation() : void
{
$serviceLocator = new ServiceManager();

$serviceLocator->setService('stubbed_logger', $this->getMockForAbstractClass(Logger::class));

$serviceLocator->setService(
Expand Down Expand Up @@ -97,15 +97,16 @@ public function testCreation() : void
'types' => [$typeName = 'foo_type' => $typeClassName = CustomType::class],
'classMetadataFactoryName' => 'stdClass',
'repositoryFactory' => CustomRepositoryFactory::class,
'default_document_repository_class_name' => CustomDocumentRepository::class,
],
],
],
]
);

$factory = new ConfigurationFactory('odm_test');

$config = $factory->createService($serviceLocator);

assert($config instanceof Configuration);

self::assertInstanceOf(Configuration::class, $config);
Expand All @@ -130,5 +131,7 @@ public function testCreation() : void

self::assertInstanceOf($typeClassName, Type::getType($typeName));
self::assertSame($repositoryFactory, $config->getRepositoryFactory());

self::assertSame(CustomDocumentRepository::class, $config->getDefaultDocumentRepositoryClassName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php declare(strict_types=1);

namespace DoctrineMongoODMModuleTest\Doctrine;

use DoctrineMongoODMModuleTest\AbstractTest;
use DoctrineMongoODMModuleTest\Assets\Document\Simple;
use DoctrineMongoODMModuleTest\Assets\DefaultDocumentRepository;

final class CustomDefaultRepositoryTest extends AbstractTest
{
public function testCustomDefaultRepository() : void
{
$documentManager = $this->getDocumentManager();

$repository = $documentManager->getRepository(Simple::class);

self::assertInstanceOf(DefaultDocumentRepository::class, $repository);
self::assertTrue($repository->isCustomDefaultDocumentRepository());
}
}
5 changes: 3 additions & 2 deletions tests/testing.config.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
<?php declare(strict_types=1);

declare(strict_types=1);
namespace DoctrineMongoODMModuleTest;

return [
'doctrine' => [
Expand All @@ -9,6 +9,7 @@
'default_db' => 'doctrineMongoODMModuleTest',
'retryConnect' => 123,
'retryQuery' => 456,
'default_document_repository_class_name' => Assets\DefaultDocumentRepository::class,
],
],
'connection' => [
Expand Down

0 comments on commit 84ff4db

Please sign in to comment.