1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\Tests\Large\G\Entity\Validation; |
4
|
|
|
|
5
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Testing\Fixtures\Modifiers\AddAssociationEntitiesModifier; |
6
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Validation\Initialiser; |
7
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\AbstractLargeTest; |
8
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\GetGeneratedCodeContainerTrait; |
9
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\TestCodeGenerator; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @large |
13
|
|
|
* @covers \EdmondsCommerce\DoctrineStaticMeta\Entity\Validation\Initialiser |
14
|
|
|
*/ |
15
|
|
|
class InitialiserTest extends AbstractLargeTest |
16
|
|
|
{ |
17
|
|
|
use GetGeneratedCodeContainerTrait; |
18
|
|
|
|
19
|
|
|
public const WORK_DIR = self::VAR_PATH . '/' . self::TEST_TYPE_MEDIUM . '/InitialiserTest'; |
20
|
|
|
|
21
|
|
|
private const TEST_ENTITY_FQN = self::TEST_ENTITIES_ROOT_NAMESPACE . TestCodeGenerator::TEST_ENTITY_PERSON; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
private $testEntityFqn; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var Initialiser |
30
|
|
|
*/ |
31
|
|
|
private $initialiser; |
32
|
|
|
|
33
|
|
|
public function setUp() |
34
|
|
|
{ |
35
|
|
|
parent::setUp(); |
36
|
|
|
$this->generateTestCode(); |
37
|
|
|
$this->setupCopiedWorkDir(); |
38
|
|
|
$this->testEntityFqn = $this->getCopiedFqn(self::TEST_ENTITY_FQN); |
39
|
|
|
$this->setupDbWithFixtures(); |
40
|
|
|
$this->initialiser = $this->container->get(Initialiser::class); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Sets up the DB with the Person Fixture |
45
|
|
|
* |
46
|
|
|
* uses the AddAssociationEntitiesModifier to ensure that the Person objects have the full data |
47
|
|
|
* |
48
|
|
|
* @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException |
49
|
|
|
*/ |
50
|
|
|
private function setupDbWithFixtures(): void |
51
|
|
|
{ |
52
|
|
|
$fixturesHelper = $this->getFixturesHelper(); |
53
|
|
|
$fixturesHelper->createDb( |
54
|
|
|
$fixturesHelper->createFixture( |
55
|
|
|
$this->getNamespaceHelper()->getFixtureFqnFromEntityFqn($this->testEntityFqn), |
56
|
|
|
new AddAssociationEntitiesModifier($this->getTestEntityGeneratorFactory()) |
57
|
|
|
) |
58
|
|
|
); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @test |
63
|
|
|
* @large |
64
|
|
|
*/ |
65
|
|
|
public function itInitialisesAProxy(): void |
66
|
|
|
{ |
67
|
|
|
$loaded = $this->getRepositoryFactory()->getRepository($this->testEntityFqn)->findOneBy([]); |
68
|
|
|
/** |
69
|
|
|
* @var \Doctrine\ORM\Proxy\Proxy |
70
|
|
|
*/ |
71
|
|
|
$attributesAddressProxy = $loaded->getAttributesAddress(); |
|
|
|
|
72
|
|
|
$expected = false; |
73
|
|
|
$actual = $attributesAddressProxy->__isInitialized__; |
74
|
|
|
self::assertSame($expected, $actual); |
75
|
|
|
|
76
|
|
|
$this->initialiser->initialise($attributesAddressProxy); |
77
|
|
|
$expected = true; |
78
|
|
|
$actual = $attributesAddressProxy->__isInitialized__; |
79
|
|
|
self::assertSame($expected, $actual); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @test |
85
|
|
|
* @large |
86
|
|
|
*/ |
87
|
|
|
public function itInitalisesAnEntityThatHasUninitialisedCollections(): void |
88
|
|
|
{ |
89
|
|
|
$loaded = $this->getRepositoryFactory()->getRepository($this->testEntityFqn)->findOneBy([]); |
90
|
|
|
/** |
91
|
|
|
* @var \Doctrine\ORM\Proxy\Proxy |
92
|
|
|
*/ |
93
|
|
|
$attributesAddressProxy = $loaded->getAttributesAddress(); |
94
|
|
|
$expected = false; |
95
|
|
|
$actual = $attributesAddressProxy->__isInitialized__; |
96
|
|
|
self::assertSame($expected, $actual); |
97
|
|
|
|
98
|
|
|
$this->initialiser->initialise($loaded); |
|
|
|
|
99
|
|
|
$expected = true; |
100
|
|
|
$actual = $attributesAddressProxy->__isInitialized__; |
101
|
|
|
self::assertSame($expected, $actual); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.