Skip to content

Commit c6a6212

Browse files
committed
Add test with composite identifier with association and custom generators
1 parent 1dbd8dc commit c6a6212

File tree

4 files changed

+110
-0
lines changed

4 files changed

+110
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
}

tests/Doctrine/Tests/ORM/Functional/ValueGeneratorsTest.php

+20
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
namespace Doctrine\Tests\ORM\Functional;
55

6+
use Doctrine\Tests\Models\ValueGenerators\AssociationIdentifier;
7+
use Doctrine\Tests\Models\ValueGenerators\AssociationIdentifierTarget;
68
use Doctrine\Tests\Models\ValueGenerators\BarGenerator;
79
use Doctrine\Tests\Models\ValueGenerators\CompositeGeneratedIdentifier;
810
use Doctrine\Tests\Models\ValueGenerators\FooGenerator;
@@ -82,4 +84,22 @@ public function testValueGeneratorsInInheritance() : void
8284
$this->assertSame(FooGenerator::VALUE, $childBEntity->getA());
8385
$this->assertSame(BarGenerator::VALUE, $childBEntity->getB());
8486
}
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+
}
85105
}

tests/Doctrine/Tests/OrmFunctionalTestCase.php

+4
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
321321
Models\ValueGenerators\InheritanceGeneratorsRoot::class,
322322
Models\ValueGenerators\InheritanceGeneratorsChildA::class,
323323
Models\ValueGenerators\InheritanceGeneratorsChildB::class,
324+
Models\ValueGenerators\AssociationIdentifier::class,
325+
Models\ValueGenerators\AssociationIdentifierTarget::class,
324326
],
325327
];
326328

@@ -611,6 +613,8 @@ protected function tearDown()
611613
$conn->executeUpdate('DELETE FROM vg_composite_generated_identifier');
612614
$conn->executeUpdate('DELETE FROM vg_non_identifier_generators');
613615
$conn->executeUpdate('DELETE FROM vg_inheritance_generators');
616+
$conn->executeUpdate('DELETE FROM vg_association_identifier');
617+
$conn->executeUpdate('DELETE FROM vg_association_identifier_target');
614618
}
615619

616620
$this->em->clear();

0 commit comments

Comments
 (0)