Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt to new type hierarchy #776

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ parameters:
- src
- tests
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
- vendor/jangregor/phpstan-prophecy/extension.neon
8 changes: 3 additions & 5 deletions src/Service/DriverFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,19 @@
namespace DoctrineModule\Service;

use Doctrine\Common\Annotations;
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
use Doctrine\Persistence\Mapping\Driver\AnnotationDriver;
use Doctrine\Persistence\Mapping\Driver\DefaultFileLocator;
use Doctrine\Persistence\Mapping\Driver\FileDriver;
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
use DoctrineModule\Options\Driver;
use Interop\Container\ContainerInterface;
use InvalidArgumentException;
use ReflectionClass;
use RuntimeException;

use function class_exists;
use function get_class;
use function interface_exists;
use function is_subclass_of;
use function sprintf;

/**
Expand Down Expand Up @@ -70,10 +68,10 @@ protected function createDriver(ContainerInterface $container, Driver $options):
// Not all drivers (DriverChain) require paths.
$paths = $options->getPaths();

$constructor = (new ReflectionClass($class))->getConstructor();
// Special options for AnnotationDrivers.
if (
$class !== AttributeDriver::class &&
($class === AnnotationDriver::class || is_subclass_of($class, AnnotationDriver::class))
$constructor !== null && $constructor->getNumberOfParameters() === 2
) {
$reader = new Annotations\AnnotationReader();
$reader = new Annotations\CachedReader(
Expand Down
27 changes: 27 additions & 0 deletions tests/Service/DriverFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace DoctrineModuleTest\Service;

use Doctrine\Common\Annotations\Reader;
use Doctrine\Common\Cache\ArrayCache;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
use DoctrineModule\Service\DriverFactory;
Expand Down Expand Up @@ -90,4 +93,28 @@ public function testCreateAttributeDriver(): void
$driver = $factory->__invoke($serviceManager, AttributeDriver::class);
$this->assertInstanceOf(AttributeDriver::class, $driver);
}

public function testCreateAnnotationDriver(): void
{
$serviceManager = new ServiceManager();
$serviceManager->setService(
'config',
[
'doctrine' => [
'driver' => [
'testDriver' => ['class' => AnnotationDriver::class],
],
],
]
);
$serviceManager->setService(
'doctrine.cache.array',
new ArrayCache()
);

$factory = new DriverFactory('testDriver');
$driver = $factory->__invoke($serviceManager, AnnotationDriver::class);
$this->assertInstanceOf(AnnotationDriver::class, $driver);
$this->assertInstanceOf(Reader::class, $driver->getReader());
}
}