1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Doctrine\Tests\ORM\Functional; |
||
6 | |||
7 | use Doctrine\Tests\Models\VersionedOneToOne\FirstRelatedEntity; |
||
8 | use Doctrine\Tests\Models\VersionedOneToOne\SecondRelatedEntity; |
||
9 | use Doctrine\ORM\ORMException; |
||
10 | use Doctrine\Tests\OrmFunctionalTestCase; |
||
11 | |||
12 | /** |
||
13 | * Tests that an entity with a OneToOne relationship defined as the id, with a version field can be created. |
||
14 | * |
||
15 | * @author Rob Caiger <[email protected]> |
||
16 | * |
||
17 | * @group VersionedOneToOne |
||
18 | */ |
||
19 | class VersionedOneToOneTest extends OrmFunctionalTestCase |
||
20 | { |
||
21 | protected function setUp() |
||
22 | { |
||
23 | parent::setUp(); |
||
24 | |||
25 | try { |
||
26 | $this->schemaTool->createSchema( |
||
27 | [ |
||
28 | $this->em->getClassMetadata(FirstRelatedEntity::class), |
||
29 | $this->em->getClassMetadata(SecondRelatedEntity::class) |
||
30 | ] |
||
31 | ); |
||
32 | } catch (ORMException $e) { |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
Loading history...
|
|||
33 | } |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * This test case tests that a versionable entity, that has a oneToOne relationship as it's id can be created |
||
38 | * without this bug fix (DDC-3318), you could not do this |
||
39 | */ |
||
40 | public function testSetVersionOnCreate() |
||
41 | { |
||
42 | $secondRelatedEntity = new SecondRelatedEntity(); |
||
43 | $secondRelatedEntity->name = 'Bob'; |
||
44 | |||
45 | $this->em->persist($secondRelatedEntity); |
||
46 | $this->em->flush(); |
||
47 | |||
48 | $firstRelatedEntity = new FirstRelatedEntity(); |
||
49 | $firstRelatedEntity->name = 'Fred'; |
||
50 | $firstRelatedEntity->secondEntity = $secondRelatedEntity; |
||
51 | |||
52 | $this->em->persist($firstRelatedEntity); |
||
53 | $this->em->flush(); |
||
54 | |||
55 | $firstEntity = $this->em->getRepository(FirstRelatedEntity::class) |
||
56 | ->findOneBy(['name' => 'Fred']); |
||
57 | |||
58 | $secondEntity = $this->em->getRepository(SecondRelatedEntity::class) |
||
59 | ->findOneBy(['name' => 'Bob']); |
||
60 | |||
61 | self::assertSame($firstRelatedEntity, $firstEntity); |
||
62 | self::assertSame($secondRelatedEntity, $secondEntity); |
||
63 | self::assertSame($firstEntity->secondEntity, $secondEntity); |
||
64 | } |
||
65 | } |
||
66 |