2015-11-27 17:28:45 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\ORM\Functional;
|
|
|
|
|
|
|
|
use Doctrine\ORM\OptimisticLockException;
|
|
|
|
use Doctrine\ORM\ORMException;
|
|
|
|
use Doctrine\Tests\Models\VersionedOneToMany\Article;
|
|
|
|
use Doctrine\Tests\Models\VersionedOneToMany\Category;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group MergeVersionedOneToMany
|
|
|
|
*/
|
|
|
|
class MergeVersionedOneToManyTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|
|
|
{
|
|
|
|
protected function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
try {
|
|
|
|
$this->_schemaTool->createSchema(
|
|
|
|
[
|
2015-11-30 10:35:42 +01:00
|
|
|
$this->_em->getClassMetadata('Doctrine\Tests\Models\VersionedOneToMany\Category'),
|
|
|
|
$this->_em->getClassMetadata('Doctrine\Tests\Models\VersionedOneToMany\Article'),
|
2015-11-27 17:28:45 +01:00
|
|
|
]
|
|
|
|
);
|
|
|
|
} catch (ORMException $e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-12-02 14:09:14 +01:00
|
|
|
* This test case asserts that a detached and unmodified entity could be merge without firing
|
|
|
|
* OptimisticLockException.
|
2015-11-27 17:28:45 +01:00
|
|
|
*/
|
|
|
|
public function testSetVersionOnCreate()
|
|
|
|
{
|
|
|
|
$category = new Category();
|
|
|
|
$category->name = 'Category';
|
|
|
|
|
|
|
|
$article = new Article();
|
|
|
|
$article->name = 'Article';
|
|
|
|
$article->category = $category;
|
|
|
|
|
|
|
|
$this->_em->persist($article);
|
|
|
|
$this->_em->flush();
|
|
|
|
$this->_em->clear();
|
|
|
|
|
2015-11-30 10:35:42 +01:00
|
|
|
$articleMerged = $this->_em->merge($article);
|
2015-11-27 17:28:45 +01:00
|
|
|
|
|
|
|
$articleMerged->name = 'Article Merged';
|
|
|
|
|
2015-11-30 10:35:42 +01:00
|
|
|
$this->_em->flush();
|
|
|
|
$this->assertEquals(2, $articleMerged->version);
|
2015-11-27 17:28:45 +01:00
|
|
|
}
|
|
|
|
}
|