|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\DBAL\LockMode; |
|
6
|
|
|
use Doctrine\Tests\Models\Company\CompanyManager; |
|
7
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
|
8
|
|
|
use Doctrine\Tests\TestUtil; |
|
9
|
|
|
|
|
10
|
|
|
class DDC933Test extends OrmFunctionalTestCase |
|
11
|
|
|
{ |
|
12
|
|
|
public function setUp() |
|
13
|
|
|
{ |
|
14
|
|
|
$this->useModelSet('company'); |
|
15
|
|
|
|
|
16
|
|
|
parent::setUp(); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @group DDC-933 |
|
21
|
|
|
*/ |
|
22
|
|
|
public function testLockCTIClass() |
|
23
|
|
|
{ |
|
24
|
|
|
if ($this->_em->getConnection()->getDatabasePlatform()->getName() === 'sqlite') { |
|
25
|
|
|
self::markTestSkipped('It should not run on in-memory databases'); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
$manager = new CompanyManager(); |
|
29
|
|
|
$manager->setName('beberlei'); |
|
30
|
|
|
$manager->setSalary(1234); |
|
31
|
|
|
$manager->setTitle('Vice President of This Test'); |
|
32
|
|
|
$manager->setDepartment("Foo"); |
|
33
|
|
|
|
|
34
|
|
|
$this->_em->persist($manager); |
|
35
|
|
|
$this->_em->flush(); |
|
36
|
|
|
|
|
37
|
|
|
$this->_em->beginTransaction(); |
|
38
|
|
|
$this->_em->lock($manager, LockMode::PESSIMISTIC_READ); |
|
39
|
|
|
$this->_em->rollback(); |
|
40
|
|
|
|
|
41
|
|
|
// if lock hasn't been released we'd have an exception here |
|
42
|
|
|
$this->assertManagerCanBeUpdatedOnAnotherConnection($manager->getId(), 'Master of This Test'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param int $id |
|
47
|
|
|
* @param string $newName |
|
48
|
|
|
* |
|
49
|
|
|
* @return void |
|
50
|
|
|
* |
|
51
|
|
|
* @throws \Doctrine\Common\Persistence\Mapping\MappingException |
|
52
|
|
|
* @throws \Doctrine\ORM\ORMException |
|
53
|
|
|
* @throws \Doctrine\ORM\OptimisticLockException |
|
54
|
|
|
* @throws \Doctrine\ORM\TransactionRequiredException |
|
55
|
|
|
*/ |
|
56
|
|
|
private function assertManagerCanBeUpdatedOnAnotherConnection(int $id, string $newName) |
|
57
|
|
|
{ |
|
58
|
|
|
$em = $this->_getEntityManager(TestUtil::getConnection()); |
|
59
|
|
|
|
|
60
|
|
|
/** @var CompanyManager $manager */ |
|
61
|
|
|
$manager = $em->find(CompanyManager::class, $id); |
|
62
|
|
|
$manager->setName($newName); |
|
63
|
|
|
|
|
64
|
|
|
$em->flush(); |
|
65
|
|
|
$em->clear(); |
|
66
|
|
|
|
|
67
|
|
|
self::assertSame($newName, $em->find(CompanyManager::class, $id)->getName()); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|