-
Notifications
You must be signed in to change notification settings - Fork 25
Add global basename support #17
Changes from 8 commits
80bd4c1
bb2135c
fc97f51
77c67e2
16ea133
1c2aad7
175e8d5
da65f82
6a10096
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,7 @@ | |
'paths' => [], | ||
'extension' => null, | ||
'drivers' => [], | ||
'global_basename' => null, | ||
] | ||
], | ||
'cache' => [ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
/** | ||
* @license See the file LICENSE for copying permission | ||
*/ | ||
|
||
namespace ContainerInteropDoctrineTest; | ||
|
||
use Doctrine\ORM\Mapping\Driver; | ||
use OutOfBoundsException; | ||
use ContainerInteropDoctrine\DriverFactory; | ||
use Interop\Container\ContainerInterface; | ||
use PHPUnit_Framework_TestCase as TestCase; | ||
|
||
class DriverFactoryTest extends TestCase | ||
{ | ||
public function testMissingClassKeyWillReturnOutOfBoundException() | ||
{ | ||
$container = $this->prophesize(ContainerInterface::class); | ||
$factory = new DriverFactory(); | ||
|
||
$this->setExpectedException(OutOfBoundsException::class, 'Missing "class" config key'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh never mind, I see There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Feel free to update the PHPUnit version. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @DASPRiD I'll do that in different PR if that's ok for you |
||
|
||
$factory($container->reveal()); | ||
} | ||
|
||
public function testItSupportsGlobalBasenameOptionOnFileDrivers() | ||
{ | ||
$globalBasename = 'foobar'; | ||
|
||
$container = $this->prophesize(ContainerInterface::class); | ||
$container->has('config')->willReturn(true); | ||
$container->get('config')->willReturn([ | ||
'doctrine' => [ | ||
'driver' => [ | ||
'orm_default' => [ | ||
'class' => TestAsset\StubFileDriver::class, | ||
'global_basename' => $globalBasename | ||
], | ||
], | ||
], | ||
]); | ||
|
||
$factory = new DriverFactory(); | ||
|
||
$driver = $factory($container->reveal()); | ||
$this->assertSame($globalBasename, $driver->getGlobalBasename()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
/** | ||
* @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()); | ||
$this->assertInstanceOf($driverClass, $driver); | ||
$this->assertSame($extension, $driver->getLocator()->getFileExtension()); | ||
} | ||
|
||
public function simplifiedDriverClassProvider() | ||
{ | ||
return [ | ||
[ Driver\SimplifiedXmlDriver::class ], | ||
[ Driver\SimplifiedYamlDriver::class ], | ||
]; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
/** | ||
* @license See the file LICENSE for copying permission | ||
*/ | ||
|
||
namespace ContainerInteropDoctrineTest\TestAsset; | ||
|
||
use Doctrine\Common\Persistence\Mapping\ClassMetadata; | ||
use Doctrine\Common\Persistence\Mapping\Driver\FileDriver; | ||
|
||
class StubFileDriver extends FileDriver | ||
{ | ||
protected function loadMappingFile($file) | ||
{ | ||
return []; | ||
} | ||
|
||
public function loadMetadataForClass($className, ClassMetadata $metadata) | ||
{ | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it is_subclass_of check is already done above, can't this if be moved inside there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tried that, you would end up repeating the constructor invocation two times anyway, because a
FileDriver
may or may not have anextension
parameter.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyway: use
array_key_exists()
instead ofisset()
.