2010-02-25 22:58:39 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\ORM\Mapping;
|
|
|
|
|
2011-02-16 19:24:42 +03:00
|
|
|
use Doctrine\ORM\Mapping\Driver\Driver;
|
2010-02-25 22:58:39 +03:00
|
|
|
use Doctrine\ORM\Mapping\Driver\DriverChain;
|
|
|
|
|
|
|
|
require_once __DIR__ . '/../../TestInit.php';
|
|
|
|
|
|
|
|
class DriverChainTest extends \Doctrine\Tests\OrmTestCase
|
|
|
|
{
|
|
|
|
public function testDelegateToMatchingNamespaceDriver()
|
|
|
|
{
|
|
|
|
$className = 'Doctrine\Tests\ORM\Mapping\DriverChainEntity';
|
|
|
|
$classMetadata = new \Doctrine\ORM\Mapping\ClassMetadata($className);
|
|
|
|
|
|
|
|
$chain = new DriverChain();
|
|
|
|
|
2011-02-16 19:24:42 +03:00
|
|
|
$driver1 = $this->getMock('Doctrine\ORM\Mapping\Driver\Driver');
|
2010-02-25 22:58:39 +03:00
|
|
|
$driver1->expects($this->never())
|
|
|
|
->method('loadMetadataForClass');
|
|
|
|
$driver1->expectS($this->never())
|
|
|
|
->method('isTransient');
|
|
|
|
|
2011-02-16 19:24:42 +03:00
|
|
|
$driver2 = $this->getMock('Doctrine\ORM\Mapping\Driver\Driver');
|
2010-02-25 22:58:39 +03:00
|
|
|
$driver2->expects($this->at(0))
|
|
|
|
->method('loadMetadataForClass')
|
|
|
|
->with($this->equalTo($className), $this->equalTo($classMetadata));
|
|
|
|
$driver2->expects($this->at(1))
|
|
|
|
->method('isTransient')
|
|
|
|
->with($this->equalTo($className))
|
|
|
|
->will($this->returnValue( true ));
|
|
|
|
|
|
|
|
$chain->addDriver($driver1, 'Doctrine\Tests\Models\Company');
|
|
|
|
$chain->addDriver($driver2, 'Doctrine\Tests\ORM\Mapping');
|
|
|
|
|
|
|
|
$chain->loadMetadataForClass($className, $classMetadata);
|
|
|
|
|
|
|
|
$this->assertTrue( $chain->isTransient($className) );
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testLoadMetadata_NoDelegatorFound_ThrowsMappingException()
|
|
|
|
{
|
|
|
|
$className = 'Doctrine\Tests\ORM\Mapping\DriverChainEntity';
|
|
|
|
$classMetadata = new \Doctrine\ORM\Mapping\ClassMetadata($className);
|
|
|
|
|
|
|
|
$chain = new DriverChain();
|
|
|
|
|
|
|
|
$this->setExpectedException('Doctrine\ORM\Mapping\MappingException');
|
|
|
|
$chain->loadMetadataForClass($className, $classMetadata);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGatherAllClassNames()
|
|
|
|
{
|
|
|
|
$className = 'Doctrine\Tests\ORM\Mapping\DriverChainEntity';
|
|
|
|
$classMetadata = new \Doctrine\ORM\Mapping\ClassMetadata($className);
|
|
|
|
|
|
|
|
$chain = new DriverChain();
|
|
|
|
|
2011-02-16 19:24:42 +03:00
|
|
|
$driver1 = $this->getMock('Doctrine\ORM\Mapping\Driver\Driver');
|
2010-02-25 22:58:39 +03:00
|
|
|
$driver1->expects($this->once())
|
|
|
|
->method('getAllClassNames')
|
2010-12-09 01:29:21 +03:00
|
|
|
->will($this->returnValue(array('Doctrine\Tests\Models\Company\Foo')));
|
2010-02-25 22:58:39 +03:00
|
|
|
|
2011-02-16 19:24:42 +03:00
|
|
|
$driver2 = $this->getMock('Doctrine\ORM\Mapping\Driver\Driver');
|
2010-02-25 22:58:39 +03:00
|
|
|
$driver2->expects($this->once())
|
|
|
|
->method('getAllClassNames')
|
2010-12-09 01:29:21 +03:00
|
|
|
->will($this->returnValue(array('Doctrine\Tests\ORM\Mapping\Bar', 'Doctrine\Tests\ORM\Mapping\Baz', 'FooBarBaz')));
|
2010-02-25 22:58:39 +03:00
|
|
|
|
|
|
|
$chain->addDriver($driver1, 'Doctrine\Tests\Models\Company');
|
|
|
|
$chain->addDriver($driver2, 'Doctrine\Tests\ORM\Mapping');
|
|
|
|
|
2010-12-09 01:29:21 +03:00
|
|
|
$this->assertEquals(array(
|
|
|
|
'Doctrine\Tests\Models\Company\Foo',
|
|
|
|
'Doctrine\Tests\ORM\Mapping\Bar',
|
|
|
|
'Doctrine\Tests\ORM\Mapping\Baz'
|
|
|
|
), $chain->getAllClassNames());
|
2010-02-25 22:58:39 +03:00
|
|
|
}
|
2010-07-21 23:20:55 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @group DDC-706
|
|
|
|
*/
|
|
|
|
public function testIsTransient()
|
2011-05-25 02:26:20 +04:00
|
|
|
{
|
2010-07-21 23:20:55 +04:00
|
|
|
$chain = new DriverChain();
|
2011-05-25 02:26:20 +04:00
|
|
|
$chain->addDriver($this->createAnnotationDriver(), 'Doctrine\Tests\Models\CMS');
|
2010-07-21 23:20:55 +04:00
|
|
|
|
|
|
|
$this->assertTrue($chain->isTransient('stdClass'), "stdClass isTransient");
|
|
|
|
$this->assertFalse($chain->isTransient('Doctrine\Tests\Models\CMS\CmsUser'), "CmsUser is not Transient");
|
|
|
|
}
|
2010-02-25 22:58:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
class DriverChainEntity
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|