File tree 4 files changed +110
-0
lines changed
4 files changed +110
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Doctrine \Tests \Models \ValueGenerators ;
6
+
7
+ use Doctrine \ORM \Annotation as ORM ;
8
+
9
+ /**
10
+ * @ORM\Entity
11
+ * @ORM\Table("vg_association_identifier")
12
+ */
13
+ class AssociationIdentifier
14
+ {
15
+ /**
16
+ * @ORM\Column(type="string")
17
+ * @ORM\Id
18
+ * @ORM\GeneratedValue("CUSTOM")
19
+ * @ORM\CustomIdGenerator("Doctrine\Tests\Models\ValueGenerators\FooGenerator")
20
+ * @var string|null
21
+ */
22
+ private $ id ;
23
+
24
+ /**
25
+ * @ORM\OneToOne(targetEntity="AssociationIdentifierTarget", cascade={"persist"})
26
+ * @ORM\Id
27
+ * @var AssociationIdentifierTarget
28
+ */
29
+ private $ target ;
30
+
31
+ /**
32
+ * @ORM\Column(type="string")
33
+ * @ORM\GeneratedValue("CUSTOM")
34
+ * @ORM\CustomIdGenerator("Doctrine\Tests\Models\ValueGenerators\BarGenerator")
35
+ * @var string|null
36
+ */
37
+ private $ regular ;
38
+
39
+ public function __construct ()
40
+ {
41
+ $ this ->target = new AssociationIdentifierTarget ();
42
+ }
43
+
44
+ public function getTarget () : AssociationIdentifierTarget
45
+ {
46
+ return $ this ->target ;
47
+ }
48
+
49
+ public function getId () : ?string
50
+ {
51
+ return $ this ->id ;
52
+ }
53
+
54
+ public function getRegular () : ?string
55
+ {
56
+ return $ this ->regular ;
57
+ }
58
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Doctrine \Tests \Models \ValueGenerators ;
6
+
7
+ use Doctrine \ORM \Annotation as ORM ;
8
+
9
+ /**
10
+ * @ORM\Entity
11
+ * @ORM\Table("vg_association_identifier_target")
12
+ */
13
+ class AssociationIdentifierTarget
14
+ {
15
+ public const ID = 123 ;
16
+
17
+ /**
18
+ * @ORM\Column(type="integer")
19
+ * @ORM\Id
20
+ * @var int
21
+ */
22
+ private $ id = self ::ID ;
23
+
24
+ public function getId () : int
25
+ {
26
+ return $ this ->id ;
27
+ }
28
+ }
Original file line number Diff line number Diff line change 3
3
4
4
namespace Doctrine \Tests \ORM \Functional ;
5
5
6
+ use Doctrine \Tests \Models \ValueGenerators \AssociationIdentifier ;
7
+ use Doctrine \Tests \Models \ValueGenerators \AssociationIdentifierTarget ;
6
8
use Doctrine \Tests \Models \ValueGenerators \BarGenerator ;
7
9
use Doctrine \Tests \Models \ValueGenerators \CompositeGeneratedIdentifier ;
8
10
use Doctrine \Tests \Models \ValueGenerators \FooGenerator ;
@@ -82,4 +84,22 @@ public function testValueGeneratorsInInheritance() : void
82
84
$ this ->assertSame (FooGenerator::VALUE , $ childBEntity ->getA ());
83
85
$ this ->assertSame (BarGenerator::VALUE , $ childBEntity ->getB ());
84
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
+ }
85
105
}
Original file line number Diff line number Diff line change @@ -321,6 +321,8 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
321
321
Models \ValueGenerators \InheritanceGeneratorsRoot::class,
322
322
Models \ValueGenerators \InheritanceGeneratorsChildA::class,
323
323
Models \ValueGenerators \InheritanceGeneratorsChildB::class,
324
+ Models \ValueGenerators \AssociationIdentifier::class,
325
+ Models \ValueGenerators \AssociationIdentifierTarget::class,
324
326
],
325
327
];
326
328
@@ -611,6 +613,8 @@ protected function tearDown()
611
613
$ conn ->executeUpdate ('DELETE FROM vg_composite_generated_identifier ' );
612
614
$ conn ->executeUpdate ('DELETE FROM vg_non_identifier_generators ' );
613
615
$ conn ->executeUpdate ('DELETE FROM vg_inheritance_generators ' );
616
+ $ conn ->executeUpdate ('DELETE FROM vg_association_identifier ' );
617
+ $ conn ->executeUpdate ('DELETE FROM vg_association_identifier_target ' );
614
618
}
615
619
616
620
$ this ->em ->clear ();
You can’t perform that action at this time.
0 commit comments