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
|
|
|
protected static $buildOnce = true; |
23
|
|
|
/** |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
private $testEntityFqn; |
27
|
|
|
/** |
28
|
|
|
* @var Initialiser |
29
|
|
|
*/ |
30
|
|
|
private $initialiser; |
31
|
|
|
|
32
|
|
|
public function setUp() |
33
|
|
|
{ |
34
|
|
|
parent::setUp(); |
35
|
|
|
$this->generateTestCode(); |
36
|
|
|
$this->setupCopiedWorkDir(); |
37
|
|
|
$this->testEntityFqn = $this->getCopiedFqn(self::TEST_ENTITY_FQN); |
38
|
|
|
$this->setupDbWithFixtures(); |
39
|
|
|
$this->initialiser = $this->container->get(Initialiser::class); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Sets up the DB with the Person Fixture |
44
|
|
|
* |
45
|
|
|
* uses the AddAssociationEntitiesModifier to ensure that the Person objects have the full data |
46
|
|
|
* |
47
|
|
|
* @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException |
48
|
|
|
*/ |
49
|
|
|
private function setupDbWithFixtures(): void |
50
|
|
|
{ |
51
|
|
|
$fixturesHelper = $this->getFixturesHelper(); |
52
|
|
|
$fixturesHelper->createDb( |
53
|
|
|
$fixturesHelper->createFixture( |
54
|
|
|
$this->getNamespaceHelper()->getFixtureFqnFromEntityFqn($this->testEntityFqn), |
55
|
|
|
new AddAssociationEntitiesModifier($this->getTestEntityGeneratorFactory()) |
56
|
|
|
) |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @test |
62
|
|
|
* @large |
63
|
|
|
*/ |
64
|
|
|
public function itInitialisesAProxy(): void |
65
|
|
|
{ |
66
|
|
|
$loaded = $this->getRepositoryFactory()->getRepository($this->testEntityFqn)->findOneBy([]); |
67
|
|
|
/** |
68
|
|
|
* @var \Doctrine\ORM\Proxy\Proxy |
69
|
|
|
*/ |
70
|
|
|
$attributesAddressProxy = $loaded->getAttributesAddress(); |
|
|
|
|
71
|
|
|
$expected = false; |
72
|
|
|
$actual = $attributesAddressProxy->__isInitialized__; |
73
|
|
|
self::assertSame($expected, $actual); |
74
|
|
|
|
75
|
|
|
$this->initialiser->initialise($attributesAddressProxy); |
76
|
|
|
$expected = true; |
77
|
|
|
$actual = $attributesAddressProxy->__isInitialized__; |
78
|
|
|
self::assertSame($expected, $actual); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @test |
84
|
|
|
* @large |
85
|
|
|
*/ |
86
|
|
|
public function itInitalisesAnEntityThatHasUninitialisedCollections(): void |
87
|
|
|
{ |
88
|
|
|
$loaded = $this->getRepositoryFactory()->getRepository($this->testEntityFqn)->findOneBy([]); |
89
|
|
|
/** |
90
|
|
|
* @var \Doctrine\ORM\Proxy\Proxy |
91
|
|
|
*/ |
92
|
|
|
$attributesAddressProxy = $loaded->getAttributesAddress(); |
93
|
|
|
$expected = false; |
94
|
|
|
$actual = $attributesAddressProxy->__isInitialized__; |
95
|
|
|
self::assertSame($expected, $actual); |
96
|
|
|
|
97
|
|
|
$this->initialiser->initialise($loaded); |
|
|
|
|
98
|
|
|
$expected = true; |
99
|
|
|
$actual = $attributesAddressProxy->__isInitialized__; |
100
|
|
|
self::assertSame($expected, $actual); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
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.