2014-08-07 14:56:27 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\ORM\Functional;
|
|
|
|
|
|
|
|
use Doctrine\Tests\Models\VersionedOneToOne\FirstRelatedEntity;
|
|
|
|
use Doctrine\Tests\Models\VersionedOneToOne\SecondRelatedEntity;
|
|
|
|
use Doctrine\ORM\ORMException;
|
2016-05-11 02:41:26 +07:00
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase;
|
2014-08-07 14:56:27 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests that an entity with a OneToOne relationship defined as the id, with a version field can be created.
|
|
|
|
*
|
|
|
|
* @author Rob Caiger <rob@clocal.co.uk>
|
|
|
|
*
|
|
|
|
* @group VersionedOneToOne
|
|
|
|
*/
|
2016-05-11 02:41:26 +07:00
|
|
|
class VersionedOneToOneTest extends OrmFunctionalTestCase
|
2014-08-07 14:56:27 +01:00
|
|
|
{
|
|
|
|
protected function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
try {
|
|
|
|
$this->_schemaTool->createSchema(
|
2016-12-07 23:33:41 +01:00
|
|
|
[
|
2014-08-07 14:56:27 +01:00
|
|
|
$this->_em->getClassMetadata('Doctrine\Tests\Models\VersionedOneToOne\FirstRelatedEntity'),
|
|
|
|
$this->_em->getClassMetadata('Doctrine\Tests\Models\VersionedOneToOne\SecondRelatedEntity')
|
2016-12-07 23:33:41 +01:00
|
|
|
]
|
2014-08-07 14:56:27 +01:00
|
|
|
);
|
|
|
|
} catch (ORMException $e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This test case tests that a versionable entity, that has a oneToOne relationship as it's id can be created
|
|
|
|
* without this bug fix (DDC-3318), you could not do this
|
|
|
|
*/
|
|
|
|
public function testSetVersionOnCreate()
|
|
|
|
{
|
|
|
|
$secondRelatedEntity = new SecondRelatedEntity();
|
|
|
|
$secondRelatedEntity->name = 'Bob';
|
|
|
|
|
|
|
|
$this->_em->persist($secondRelatedEntity);
|
|
|
|
$this->_em->flush();
|
|
|
|
|
|
|
|
$firstRelatedEntity = new FirstRelatedEntity();
|
|
|
|
$firstRelatedEntity->name = 'Fred';
|
|
|
|
$firstRelatedEntity->secondEntity = $secondRelatedEntity;
|
|
|
|
|
|
|
|
$this->_em->persist($firstRelatedEntity);
|
|
|
|
$this->_em->flush();
|
|
|
|
|
|
|
|
$firstEntity = $this->_em->getRepository('Doctrine\Tests\Models\VersionedOneToOne\FirstRelatedEntity')
|
2016-12-07 23:33:41 +01:00
|
|
|
->findOneBy(['name' => 'Fred']);
|
2014-08-07 14:56:27 +01:00
|
|
|
|
|
|
|
$secondEntity = $this->_em->getRepository('Doctrine\Tests\Models\VersionedOneToOne\SecondRelatedEntity')
|
2016-12-07 23:33:41 +01:00
|
|
|
->findOneBy(['name' => 'Bob']);
|
2014-08-07 14:56:27 +01:00
|
|
|
|
|
|
|
$this->assertSame($firstRelatedEntity, $firstEntity);
|
|
|
|
$this->assertSame($secondRelatedEntity, $secondEntity);
|
|
|
|
$this->assertSame($firstEntity->secondEntity, $secondEntity);
|
|
|
|
}
|
|
|
|
}
|