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
|
|
|
|
2010-03-15 20:19:00 +03:00
|
|
|
$this->assertEquals(array('address_id' => 'id'), $oneToOneMapping->sourceToTargetKeyColumns);
|
|
|
|
$this->assertEquals(array('id' => 'address_id'), $oneToOneMapping->targetToSourceKeyColumns);
|
|
|
|
$this->assertEquals('Address', $oneToOneMapping->targetEntityName);
|
|
|
|
$this->assertEquals('Person', $oneToOneMapping->sourceEntityName);
|
|
|
|
$this->assertEquals('address', $oneToOneMapping->sourceFieldName);
|
|
|
|
$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);
|
2010-03-15 20:19:00 +03:00
|
|
|
$this->assertEquals('address', $oneToOneMapping->mappedBy);
|
|
|
|
$this->assertEquals('Address', $oneToOneMapping->sourceEntityName);
|
|
|
|
$this->assertEquals('Person', $oneToOneMapping->targetEntityName);
|
2010-03-29 17:20:41 +04:00
|
|
|
$this->assertTrue( ! $oneToOneMapping->isOwningSide);
|
2008-07-21 00:13:24 +04:00
|
|
|
}
|
2009-02-18 10:59:11 +03:00
|
|
|
}
|