Skip to content
This repository has been archived by the owner on Mar 27, 2022. It is now read-only.

Commit

Permalink
make DriverFactory able to build Simplified* drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanotorresi committed Feb 1, 2017
1 parent 77c67e2 commit 16ea133
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/DriverFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,16 @@ protected function createWithConfig(ContainerInterface $container, $configKey)
),
$config['paths']
);
} else {
$driver = new $config['class']($config['paths']);
}

if (null !== $config['extension'] && $driver instanceof FileDriver) {
$locator = $driver->getLocator();

if (get_class($locator) !== DefaultFileLocator::class) {
throw new Exception\DomainException(sprintf(
'File locator must be a concrete instance of %s, got %s',
DefaultFileLocator::class,
get_class($locator)
));
}
if (null !== $config['extension']
&& (FileDriver::class === $config['class'] || is_subclass_of($config['class'], FileDriver::class))
) {
$driver = new $config['class']($config['paths'], $config['extension']);
}

$driver->setLocator(new DefaultFileLocator($locator->getPaths(), $config['extension']));
if (! isset($driver)) {
$driver = new $config['class']($config['paths']);
}

if (isset($config['global_basename']) && $driver instanceof FileDriver) {
Expand Down
39 changes: 39 additions & 0 deletions test/DriverFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace ContainerInteropDoctrineTest;

use Doctrine\ORM\Mapping\Driver;
use OutOfBoundsException;
use ContainerInteropDoctrine\DriverFactory;
use Interop\Container\ContainerInterface;
Expand Down Expand Up @@ -44,4 +45,42 @@ public function testItSupportsGlobalBasenameOptionOnFileDrivers()
$driver = $factory($container->reveal());
static::assertSame($globalBasename, $driver->getGlobalBasename());
}

/**
* @param string $driverClass
*
* @dataProvider simplifiedDriverClassProvider
*/
public function testItSupportsSettingExtensionInDriversUsingSymfonyFileLocator($driverClass)
{
$extension = '.foo.bar';

$container = $this->prophesize(ContainerInterface::class);
$container->has('config')->willReturn(true);
$container->get('config')->willReturn([
'doctrine' => [
'driver' => [
'orm_default' => [
'class' => $driverClass,
'extension' => $extension,
],
],
],
]);

$factory = new DriverFactory();

/** @var Driver\SimplifiedXmlDriver $driver */
$driver = $factory($container->reveal());
static::assertInstanceOf($driverClass, $driver);
static::assertSame($extension, $driver->getLocator()->getFileExtension());
}

public function simplifiedDriverClassProvider()
{
return [
[ Driver\SimplifiedXmlDriver::class ],
[ Driver\SimplifiedYamlDriver::class ],
];
}
}

0 comments on commit 16ea133

Please sign in to comment.