1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
|
|
|
|
5
|
|
|
use Doctrine\ORM\Annotation as ORM; |
|
|
|
|
6
|
|
|
use Doctrine\DBAL\LockMode; |
|
|
|
|
7
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @group GH-5998 |
11
|
|
|
*/ |
12
|
|
|
class GH5998Test extends OrmFunctionalTestCase |
13
|
|
|
{ |
14
|
|
|
protected function setUp(): void |
|
|
|
|
15
|
|
|
{ |
16
|
|
|
parent::setUp(); |
17
|
|
|
$this->schemaTool->createSchema( |
18
|
|
|
[ |
19
|
|
|
$this->em->getClassMetadata(GH5998Main::class), |
|
|
|
|
20
|
|
|
$this->em->getClassMetadata(GH5998Child::class), |
|
|
|
|
21
|
|
|
] |
22
|
|
|
); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Verifies that MappedSuperclasses work within a JTI hierarchy. |
27
|
|
|
*/ |
28
|
|
|
public function testIssue() |
29
|
|
|
{ |
30
|
|
|
// Test insert |
31
|
|
|
$child = new GH5998Child('Sam', 0, 1); |
32
|
|
|
$this->em->persist($child); |
33
|
|
|
$this->em->flush(); |
34
|
|
|
$this->em->clear(); |
35
|
|
|
|
36
|
|
|
// Test find |
37
|
|
|
$child = $this->em->getRepository(GH5998Child::class)->find(1); |
38
|
|
|
self::assertNotNull($child); |
39
|
|
|
|
40
|
|
|
// Test lock and update |
41
|
|
|
$this->em->transactional(function($em) use ($child) { |
|
|
|
|
42
|
|
|
$em->lock($child, LockMode::NONE); |
43
|
|
|
$child->firstName = 'Bob'; |
44
|
|
|
$child->status = 0; |
|
|
|
|
45
|
|
|
}); |
46
|
|
|
$this->em->clear(); |
47
|
|
|
$child = $this->em->getRepository(GH5998Child::class)->find(1); |
48
|
|
|
self::assertEquals($child->firstName, 'Bob'); |
49
|
|
|
self::assertEquals($child->status, 0); |
50
|
|
|
|
51
|
|
|
// Test delete |
52
|
|
|
$this->em->remove($child); |
53
|
|
|
$this->em->flush(); |
54
|
|
|
$child = $this->em->getRepository(GH5998Child::class)->find(1); |
55
|
|
|
self::assertNull($child); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @ORM\MappedSuperclass |
61
|
|
|
*/ |
62
|
|
|
class GH5998Common |
63
|
|
|
{ |
64
|
|
|
/** |
65
|
|
|
* @ORM\Id |
66
|
|
|
* @ORM\Column(type="integer") |
67
|
|
|
* @ORM\GeneratedValue |
68
|
|
|
*/ |
69
|
|
|
public $id; |
70
|
|
|
/** |
|
|
|
|
71
|
|
|
* @ORM\Column(type="integer"); |
72
|
|
|
*/ |
73
|
|
|
public $status; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @ORM\Entity |
78
|
|
|
* @ORM\InheritanceType("JOINED") |
79
|
|
|
* @ORM\DiscriminatorMap({"child" = "Doctrine\Tests\ORM\Functional\Ticket\GH5998Child"}) |
80
|
|
|
*/ |
81
|
|
|
abstract class GH5998Main extends GH5998Common |
82
|
|
|
{ |
83
|
|
|
/** |
|
|
|
|
84
|
|
|
* @ORM\Column(type="string", length=255); |
85
|
|
|
*/ |
86
|
|
|
public $firstName; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @ORM\Entity |
91
|
|
|
*/ |
92
|
|
|
class GH5998Child extends GH5998Main |
93
|
|
|
{ |
94
|
|
|
/** |
|
|
|
|
95
|
|
|
* @ORM\Column(type="integer") |
96
|
|
|
*/ |
97
|
|
|
public $type; |
98
|
|
|
function __construct(string $firstName, int $type, int $status) |
|
|
|
|
99
|
|
|
{ |
100
|
|
|
$this->firstName = $firstName; |
101
|
|
|
$this->type = $type; |
|
|
|
|
102
|
|
|
$this->status = $status; |
|
|
|
|
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|