2008-07-21 00:13:24 +04:00
|
|
|
<?php
|
2009-01-22 22:38:10 +03:00
|
|
|
|
|
|
|
namespace Doctrine\Tests\ORM\Associations;
|
|
|
|
|
2009-01-24 19:56:44 +03:00
|
|
|
require_once __DIR__ . '/../../TestInit.php';
|
2009-02-18 10:59:11 +03:00
|
|
|
|
2009-01-22 22:38:10 +03:00
|
|
|
class OneToOneMappingTest extends \Doctrine\Tests\OrmTestCase
|
2008-07-21 00:13:24 +04:00
|
|
|
{
|
|
|
|
public function testCorrectOneToOneBidirectionalMapping()
|
|
|
|
{
|
|
|
|
$owningSideMapping = array(
|
|
|
|
'fieldName' => 'address',
|
|
|
|
'targetEntity' => 'Address',
|
2009-02-04 19:35:36 +03:00
|
|
|
'joinColumns' => array(array('name' => 'address_id', 'referencedColumnName' => 'id')),
|
2008-08-16 23:40:59 +04:00
|
|
|
'sourceEntity' => 'Person', // This is normally filled by ClassMetadata
|
2008-07-21 00:13:24 +04:00
|
|
|
);
|
|
|
|
|
2009-01-22 22:38:10 +03:00
|
|
|
$oneToOneMapping = new \Doctrine\ORM\Mapping\OneToOneMapping($owningSideMapping);
|
2008-07-21 00:13:24 +04:00
|
|
|
|
|
|
|
$this->assertEquals(array('address_id' => 'id'), $oneToOneMapping->getSourceToTargetKeyColumns());
|
|
|
|
$this->assertEquals(array('id' => 'address_id'), $oneToOneMapping->getTargetToSourceKeyColumns());
|
|
|
|
$this->assertEquals('Address', $oneToOneMapping->getTargetEntityName());
|
|
|
|
$this->assertEquals('Person', $oneToOneMapping->getSourceEntityName());
|
|
|
|
$this->assertEquals('address', $oneToOneMapping->getSourceFieldName());
|
|
|
|
$this->assertTrue($oneToOneMapping->isOwningSide());
|
2009-02-18 10:59:11 +03:00
|
|
|
|
2008-07-21 00:13:24 +04:00
|
|
|
$inverseSideMapping = array(
|
2008-08-16 23:40:59 +04:00
|
|
|
'fieldName' => 'person',
|
|
|
|
'sourceEntity' => 'Address',
|
|
|
|
'targetEntity' => 'Person',
|
2008-07-21 00:13:24 +04:00
|
|
|
'mappedBy' => 'address'
|
|
|
|
);
|
|
|
|
|
2009-01-22 22:38:10 +03:00
|
|
|
$oneToOneMapping = new \Doctrine\ORM\Mapping\OneToOneMapping($inverseSideMapping);
|
2008-07-21 00:13:24 +04:00
|
|
|
$this->assertEquals('address', $oneToOneMapping->getMappedByFieldName());
|
2008-08-16 23:40:59 +04:00
|
|
|
$this->assertEquals('Address', $oneToOneMapping->getSourceEntityName());
|
|
|
|
$this->assertEquals('Person', $oneToOneMapping->getTargetEntityName());
|
2008-07-21 00:13:24 +04:00
|
|
|
$this->assertTrue($oneToOneMapping->isInverseSide());
|
|
|
|
}
|
2009-02-18 10:59:11 +03:00
|
|
|
}
|