2011-05-19 17:03:56 +01:00
|
|
|
<?php
|
|
|
|
|
2011-05-31 09:57:06 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the Symfony framework.
|
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
|
*
|
|
|
|
* This source file is subject to the MIT license that is bundled
|
|
|
|
* with this source code in the file LICENSE.
|
|
|
|
*/
|
|
|
|
|
2011-06-08 07:36:14 +01:00
|
|
|
namespace Symfony\Tests\Bridge\Doctrine\Mapping\Driver;
|
2011-05-19 17:03:56 +01:00
|
|
|
|
|
|
|
abstract class AbstractDriverTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
public function testFindMappingFile()
|
|
|
|
{
|
|
|
|
$driver = $this->getDriver(array(
|
2011-06-08 07:36:14 +01:00
|
|
|
'MyNamespace\MySubnamespace\EntityFoo' => 'foo',
|
|
|
|
'MyNamespace\MySubnamespace\Entity' => $this->dir,
|
2011-05-19 17:03:56 +01:00
|
|
|
));
|
|
|
|
|
|
|
|
touch($filename = $this->dir.'/Foo'.$this->getFileExtension());
|
2011-06-08 07:36:14 +01:00
|
|
|
$this->assertEquals($filename, $this->invoke($driver, '_findMappingFile', array('MyNamespace\MySubnamespace\Entity\Foo')));
|
2011-05-19 17:03:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testFindMappingFileInSubnamespace()
|
|
|
|
{
|
|
|
|
$driver = $this->getDriver(array(
|
2011-06-08 07:36:14 +01:00
|
|
|
'MyNamespace\MySubnamespace\Entity' => $this->dir,
|
2011-05-19 17:03:56 +01:00
|
|
|
));
|
|
|
|
|
|
|
|
touch($filename = $this->dir.'/Foo.Bar'.$this->getFileExtension());
|
2011-06-08 07:36:14 +01:00
|
|
|
$this->assertEquals($filename, $this->invoke($driver, '_findMappingFile', array('MyNamespace\MySubnamespace\Entity\Foo\Bar')));
|
2011-05-19 17:03:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testFindMappingFileNamespacedFoundFileNotFound()
|
|
|
|
{
|
|
|
|
$this->setExpectedException(
|
|
|
|
'Doctrine\ORM\Mapping\MappingException',
|
2011-06-08 07:36:14 +01:00
|
|
|
"No mapping file found named '".$this->dir."/Foo".$this->getFileExtension()."' for class 'MyNamespace\MySubnamespace\Entity\Foo'."
|
2011-05-19 17:03:56 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$driver = $this->getDriver(array(
|
2011-06-08 07:36:14 +01:00
|
|
|
'MyNamespace\MySubnamespace\Entity' => $this->dir,
|
2011-05-19 17:03:56 +01:00
|
|
|
));
|
|
|
|
|
2011-06-08 07:36:14 +01:00
|
|
|
$this->invoke($driver, '_findMappingFile', array('MyNamespace\MySubnamespace\Entity\Foo'));
|
2011-05-19 17:03:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testFindMappingNamespaceNotFound()
|
|
|
|
{
|
|
|
|
$this->setExpectedException(
|
|
|
|
'Doctrine\ORM\Mapping\MappingException',
|
2011-06-08 07:36:14 +01:00
|
|
|
"No mapping file found named 'Foo".$this->getFileExtension()."' for class 'MyOtherNamespace\MySubnamespace\Entity\Foo'."
|
2011-05-19 17:03:56 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
$driver = $this->getDriver(array(
|
2011-06-08 07:36:14 +01:00
|
|
|
'MyNamespace\MySubnamespace\Entity' => $this->dir,
|
2011-05-19 17:03:56 +01:00
|
|
|
));
|
|
|
|
|
2011-06-08 07:36:14 +01:00
|
|
|
$this->invoke($driver, '_findMappingFile', array('MyOtherNamespace\MySubnamespace\Entity\Foo'));
|
2011-05-19 17:03:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function setUp()
|
|
|
|
{
|
2011-05-24 22:18:17 +01:00
|
|
|
if (!class_exists('Doctrine\\Common\\Version')) {
|
|
|
|
$this->markTestSkipped('Doctrine is not available.');
|
|
|
|
}
|
|
|
|
|
2011-05-19 17:03:56 +01:00
|
|
|
$this->dir = sys_get_temp_dir().'/abstract_driver_test';
|
|
|
|
@mkdir($this->dir, 0777, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function tearDown()
|
|
|
|
{
|
2011-05-29 23:24:32 +01:00
|
|
|
$iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->dir), \RecursiveIteratorIterator::CHILD_FIRST);
|
2011-05-19 17:03:56 +01:00
|
|
|
|
2011-05-29 23:24:32 +01:00
|
|
|
foreach ($iterator as $path) {
|
2011-05-19 17:03:56 +01:00
|
|
|
if ($path->isDir()) {
|
|
|
|
@rmdir($path);
|
|
|
|
} else {
|
|
|
|
@unlink($path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@rmdir($this->dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract protected function getFileExtension();
|
|
|
|
abstract protected function getDriver(array $paths = array());
|
|
|
|
|
|
|
|
private function setField($obj, $field, $value)
|
|
|
|
{
|
|
|
|
$ref = new \ReflectionProperty($obj, $field);
|
|
|
|
$ref->setAccessible(true);
|
|
|
|
$ref->setValue($obj, $value);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function invoke($obj, $method, array $args = array()) {
|
|
|
|
$ref = new \ReflectionMethod($obj, $method);
|
|
|
|
$ref->setAccessible(true);
|
|
|
|
|
|
|
|
return $ref->invokeArgs($obj, $args);
|
|
|
|
}
|
2011-06-08 18:56:59 +01:00
|
|
|
}
|