|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Doctrine\Tests\ORM\Functional; |
|
5
|
|
|
|
|
6
|
|
|
use Doctrine\Tests\Models\ValueGenerators\AssociationIdentifier; |
|
7
|
|
|
use Doctrine\Tests\Models\ValueGenerators\AssociationIdentifierTarget; |
|
8
|
|
|
use Doctrine\Tests\Models\ValueGenerators\BarGenerator; |
|
9
|
|
|
use Doctrine\Tests\Models\ValueGenerators\CompositeGeneratedIdentifier; |
|
10
|
|
|
use Doctrine\Tests\Models\ValueGenerators\FooGenerator; |
|
11
|
|
|
use Doctrine\Tests\Models\ValueGenerators\InheritanceGeneratorsChildA; |
|
12
|
|
|
use Doctrine\Tests\Models\ValueGenerators\InheritanceGeneratorsChildB; |
|
13
|
|
|
use Doctrine\Tests\Models\ValueGenerators\InheritanceGeneratorsRoot; |
|
14
|
|
|
use Doctrine\Tests\Models\ValueGenerators\NonIdentifierGenerators; |
|
15
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
|
16
|
|
|
|
|
17
|
|
|
class ValueGeneratorsTest extends OrmFunctionalTestCase |
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
|
|
public function setUp() |
|
21
|
|
|
{ |
|
22
|
|
|
$this->useModelSet('valueGenerators'); |
|
23
|
|
|
parent::setUp(); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function testCompositeIdentifierWithMultipleGenerators() : void |
|
27
|
|
|
{ |
|
28
|
|
|
$entity = new CompositeGeneratedIdentifier(); |
|
29
|
|
|
$this->em->persist($entity); |
|
30
|
|
|
$this->em->flush(); |
|
31
|
|
|
|
|
32
|
|
|
self::assertSame(FooGenerator::VALUE, $entity->getA()); |
|
33
|
|
|
self::assertSame(BarGenerator::VALUE, $entity->getB()); |
|
34
|
|
|
|
|
35
|
|
|
$this->em->clear(); |
|
36
|
|
|
|
|
37
|
|
|
$entity = $this->getEntityManager()->find( |
|
38
|
|
|
CompositeGeneratedIdentifier::class, |
|
39
|
|
|
['a' => FooGenerator::VALUE, 'b' => BarGenerator::VALUE] |
|
40
|
|
|
); |
|
41
|
|
|
self::assertNotNull($entity); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function testNonIdentifierGenerators() : void |
|
45
|
|
|
{ |
|
46
|
|
|
$entity = new NonIdentifierGenerators(); |
|
47
|
|
|
|
|
48
|
|
|
$this->em->persist($entity); |
|
49
|
|
|
$this->em->flush(); |
|
50
|
|
|
|
|
51
|
|
|
self::assertNotNull($entity->getId()); |
|
52
|
|
|
self::assertSame(FooGenerator::VALUE, $entity->getFoo()); |
|
53
|
|
|
self::assertSame(BarGenerator::VALUE, $entity->getBar()); |
|
54
|
|
|
|
|
55
|
|
|
$this->em->clear(); |
|
56
|
|
|
|
|
57
|
|
|
$entity = $this->getEntityManager()->find(NonIdentifierGenerators::class, $entity->getId()); |
|
58
|
|
|
self::assertNotNull($entity); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function testValueGeneratorsInInheritance() : void |
|
62
|
|
|
{ |
|
63
|
|
|
$rootEntity = new InheritanceGeneratorsRoot(); |
|
64
|
|
|
|
|
65
|
|
|
$this->em->persist($rootEntity); |
|
66
|
|
|
$this->em->flush(); |
|
67
|
|
|
|
|
68
|
|
|
$this->assertNotNull($rootEntity->getId()); |
|
69
|
|
|
|
|
70
|
|
|
$childAEntity = new InheritanceGeneratorsChildA(); |
|
71
|
|
|
|
|
72
|
|
|
$this->em->persist($childAEntity); |
|
73
|
|
|
$this->em->flush(); |
|
74
|
|
|
|
|
75
|
|
|
$this->assertNotNull($childAEntity); |
|
76
|
|
|
$this->assertSame(FooGenerator::VALUE, $childAEntity->getA()); |
|
77
|
|
|
|
|
78
|
|
|
$childBEntity = new InheritanceGeneratorsChildB(); |
|
79
|
|
|
|
|
80
|
|
|
$this->em->persist($childBEntity); |
|
81
|
|
|
$this->em->flush(); |
|
82
|
|
|
|
|
83
|
|
|
$this->assertNotNull($childBEntity); |
|
84
|
|
|
$this->assertSame(FooGenerator::VALUE, $childBEntity->getA()); |
|
85
|
|
|
$this->assertSame(BarGenerator::VALUE, $childBEntity->getB()); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function testGeneratorsWithAssociationInIdentifier() : void |
|
89
|
|
|
{ |
|
90
|
|
|
$entity = new AssociationIdentifier(); |
|
91
|
|
|
|
|
92
|
|
|
$this->em->persist($entity); |
|
93
|
|
|
$this->em->flush(); |
|
94
|
|
|
|
|
95
|
|
|
$this->assertSame(FooGenerator::VALUE, $entity->getId()); |
|
96
|
|
|
$this->assertSame(BarGenerator::VALUE, $entity->getRegular()); |
|
97
|
|
|
|
|
98
|
|
|
$entity = $this->em->find( |
|
99
|
|
|
AssociationIdentifier::class, |
|
100
|
|
|
['id' => FooGenerator::VALUE, 'target' => AssociationIdentifierTarget::ID] |
|
101
|
|
|
); |
|
102
|
|
|
|
|
103
|
|
|
$this->assertNotNull($entity); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|