2011-10-13 23:39:11 +02:00
< ? php
namespace Doctrine\Tests\ORM\Mapping\Symfony ;
2016-06-18 13:01:59 +02:00
use Doctrine\Common\Persistence\Mapping\MappingException ;
2011-10-13 23:39:11 +02:00
/**
* @ group DDC - 1418
*/
abstract class AbstractDriverTest extends \PHPUnit_Framework_TestCase
{
public function testFindMappingFile ()
{
2016-12-07 23:33:41 +01:00
$driver = $this -> getDriver (
[
2011-10-13 23:39:11 +02:00
'MyNamespace\MySubnamespace\EntityFoo' => 'foo' ,
'MyNamespace\MySubnamespace\Entity' => $this -> dir ,
2016-12-07 23:33:41 +01:00
]
);
2011-10-13 23:39:11 +02:00
touch ( $filename = $this -> dir . '/Foo' . $this -> getFileExtension ());
2012-01-18 00:04:25 +01:00
$this -> assertEquals ( $filename , $driver -> getLocator () -> findMappingFile ( 'MyNamespace\MySubnamespace\Entity\Foo' ));
2011-10-13 23:39:11 +02:00
}
public function testFindMappingFileInSubnamespace ()
{
2016-12-07 23:33:41 +01:00
$driver = $this -> getDriver (
[
2011-10-13 23:39:11 +02:00
'MyNamespace\MySubnamespace\Entity' => $this -> dir ,
2016-12-07 23:33:41 +01:00
]
);
2011-10-13 23:39:11 +02:00
touch ( $filename = $this -> dir . '/Foo.Bar' . $this -> getFileExtension ());
2012-01-18 00:04:25 +01:00
$this -> assertEquals ( $filename , $driver -> getLocator () -> findMappingFile ( 'MyNamespace\MySubnamespace\Entity\Foo\Bar' ));
2011-10-13 23:39:11 +02:00
}
public function testFindMappingFileNamespacedFoundFileNotFound ()
{
2016-06-18 13:01:59 +02:00
$this -> expectException ( MappingException :: class );
$this -> expectExceptionMessage ( 'No mapping file found named' );
2011-10-13 23:39:11 +02:00
2016-12-07 23:33:41 +01:00
$driver = $this -> getDriver (
[
2011-10-13 23:39:11 +02:00
'MyNamespace\MySubnamespace\Entity' => $this -> dir ,
2016-12-07 23:33:41 +01:00
]
);
2011-10-13 23:39:11 +02:00
2012-01-18 00:04:25 +01:00
$driver -> getLocator () -> findMappingFile ( 'MyNamespace\MySubnamespace\Entity\Foo' );
2011-10-13 23:39:11 +02:00
}
public function testFindMappingNamespaceNotFound ()
{
2016-06-18 13:01:59 +02:00
$this -> expectException ( MappingException :: class );
$this -> expectExceptionMessage ( " No mapping file found named 'Foo " . $this -> getFileExtension () . " ' for class 'MyOtherNamespace \ MySubnamespace \ Entity \ Foo'. " );
2011-10-13 23:39:11 +02:00
2016-12-07 23:33:41 +01:00
$driver = $this -> getDriver (
[
2011-10-13 23:39:11 +02:00
'MyNamespace\MySubnamespace\Entity' => $this -> dir ,
2016-12-07 23:33:41 +01:00
]
);
2011-10-13 23:39:11 +02:00
2012-01-18 00:04:25 +01:00
$driver -> getLocator () -> findMappingFile ( 'MyOtherNamespace\MySubnamespace\Entity\Foo' );
2011-10-13 23:39:11 +02:00
}
protected function setUp ()
{
$this -> dir = sys_get_temp_dir () . '/abstract_driver_test' ;
@ mkdir ( $this -> dir , 0777 , true );
}
protected function tearDown ()
{
$iterator = new \RecursiveIteratorIterator ( new \RecursiveDirectoryIterator ( $this -> dir ), \RecursiveIteratorIterator :: CHILD_FIRST );
foreach ( $iterator as $path ) {
if ( $path -> isDir ()) {
@ rmdir ( $path );
} else {
@ unlink ( $path );
}
}
@ rmdir ( $this -> dir );
}
abstract protected function getFileExtension ();
2016-12-07 23:33:41 +01:00
abstract protected function getDriver ( array $paths = []);
2011-10-13 23:39:11 +02:00
}