1
0
mirror of synced 2025-01-09 18:47:10 +03:00
doctrine2/tests/Doctrine/Tests/ORM/Functional/VersionedOneToOneTest.php
Rob Caiger dd398ce577 - Fixed the basic entity persister so that versioned OneToOne entities can be created
- Created an IdentifierFlattener utility class
- Moved the logic for the flatten identifier method into the new utility class
- Replaced calls for private flattenIdentifier to use new utility
- Added appropriate unit tests
2014-10-01 14:01:44 +01:00

63 lines
2.1 KiB
PHP

<?php
namespace Doctrine\Tests\ORM\Functional;
use Doctrine\Tests\Models\VersionedOneToOne\FirstRelatedEntity;
use Doctrine\Tests\Models\VersionedOneToOne\SecondRelatedEntity;
use Doctrine\ORM\ORMException;
/**
* 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
*/
class VersionedOneToOneTest extends \Doctrine\Tests\OrmFunctionalTestCase
{
protected function setUp()
{
parent::setUp();
try {
$this->_schemaTool->createSchema(
array(
$this->_em->getClassMetadata('Doctrine\Tests\Models\VersionedOneToOne\FirstRelatedEntity'),
$this->_em->getClassMetadata('Doctrine\Tests\Models\VersionedOneToOne\SecondRelatedEntity')
)
);
} 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')
->findOneBy(array('name' => 'Fred'));
$secondEntity = $this->_em->getRepository('Doctrine\Tests\Models\VersionedOneToOne\SecondRelatedEntity')
->findOneBy(array('name' => 'Bob'));
$this->assertSame($firstRelatedEntity, $firstEntity);
$this->assertSame($secondRelatedEntity, $secondEntity);
$this->assertSame($firstEntity->secondEntity, $secondEntity);
}
}