-
Notifications
You must be signed in to change notification settings - Fork 25
Add global basename support #17
Changes from 3 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,47 @@ | ||
<?php | ||
/** | ||
* @license See the file LICENSE for copying permission | ||
*/ | ||
|
||
namespace ContainerInteropDoctrineTest; | ||
|
||
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.
|
||
} | ||
} |
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()
.