9da83cfae8
* Use createMock() and getMockBuilder() instead of getMock() * Use expectException() and expectExceptionMessage() instead of setExpectedException()
97 lines
3.5 KiB
PHP
97 lines
3.5 KiB
PHP
<?php
|
|
/*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*
|
|
* This software consists of voluntary contributions made by many individuals
|
|
* and is licensed under the LGPL. For more information, see
|
|
* <http://www.doctrine-project.org>.
|
|
*/
|
|
|
|
namespace Doctrine\Tests\ORM\Mapping\Symfony;
|
|
use Doctrine\Common\Persistence\Mapping\MappingException;
|
|
|
|
/**
|
|
* @group DDC-1418
|
|
*/
|
|
abstract class AbstractDriverTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
public function testFindMappingFile()
|
|
{
|
|
$driver = $this->getDriver(array(
|
|
'MyNamespace\MySubnamespace\EntityFoo' => 'foo',
|
|
'MyNamespace\MySubnamespace\Entity' => $this->dir,
|
|
));
|
|
|
|
touch($filename = $this->dir.'/Foo'.$this->getFileExtension());
|
|
$this->assertEquals($filename, $driver->getLocator()->findMappingFile('MyNamespace\MySubnamespace\Entity\Foo'));
|
|
}
|
|
|
|
public function testFindMappingFileInSubnamespace()
|
|
{
|
|
$driver = $this->getDriver(array(
|
|
'MyNamespace\MySubnamespace\Entity' => $this->dir,
|
|
));
|
|
|
|
touch($filename = $this->dir.'/Foo.Bar'.$this->getFileExtension());
|
|
$this->assertEquals($filename, $driver->getLocator()->findMappingFile('MyNamespace\MySubnamespace\Entity\Foo\Bar'));
|
|
}
|
|
|
|
public function testFindMappingFileNamespacedFoundFileNotFound()
|
|
{
|
|
$this->expectException(MappingException::class);
|
|
$this->expectExceptionMessage('No mapping file found named');
|
|
|
|
$driver = $this->getDriver(array(
|
|
'MyNamespace\MySubnamespace\Entity' => $this->dir,
|
|
));
|
|
|
|
$driver->getLocator()->findMappingFile('MyNamespace\MySubnamespace\Entity\Foo');
|
|
}
|
|
|
|
public function testFindMappingNamespaceNotFound()
|
|
{
|
|
$this->expectException(MappingException::class);
|
|
$this->expectExceptionMessage("No mapping file found named 'Foo" . $this->getFileExtension() . "' for class 'MyOtherNamespace\MySubnamespace\Entity\Foo'.");
|
|
|
|
$driver = $this->getDriver(array(
|
|
'MyNamespace\MySubnamespace\Entity' => $this->dir,
|
|
));
|
|
|
|
$driver->getLocator()->findMappingFile('MyOtherNamespace\MySubnamespace\Entity\Foo');
|
|
}
|
|
|
|
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();
|
|
abstract protected function getDriver(array $paths = array());
|
|
}
|