1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\Tests\Small\CodeGeneration\Creation\Tests\Assets\EntityFixtures; |
4
|
|
|
|
5
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Creation\Tests\Assets\Entity\Fixtures\EntityFixtureCreator; |
6
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Filesystem\Factory\FileFactory; |
7
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Filesystem\Factory\FindReplaceFactory; |
8
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Filesystem\File\Writer; |
9
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\NamespaceHelper; |
10
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Config; |
11
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Tests\Small\ConfigTest; |
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @covers \EdmondsCommerce\DoctrineStaticMeta\CodeGeneration\Creation\Tests\Assets\Entity\Fixtures\EntityFixtureCreator |
16
|
|
|
* @small |
17
|
|
|
*/ |
18
|
|
|
class EntityFixtureCreatorTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
private const FIXTURE = '<?php declare(strict_types=1); |
21
|
|
|
|
22
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\Assets\Entity\Fixtures; |
23
|
|
|
|
24
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Testing\Fixtures\AbstractEntityFixtureLoader; |
25
|
|
|
|
26
|
|
|
class TestEntityFixture extends AbstractEntityFixtureLoader |
27
|
|
|
{ |
28
|
|
|
|
29
|
|
|
} |
30
|
|
|
'; |
31
|
|
|
|
32
|
|
|
private const NESTED_FIXTURE = '<?php declare(strict_types=1); |
33
|
|
|
|
34
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\Assets\Entity\Fixtures\Deeply\Nested\Entities; |
35
|
|
|
|
36
|
|
|
use EdmondsCommerce\DoctrineStaticMeta\Entity\Testing\Fixtures\AbstractEntityFixtureLoader; |
37
|
|
|
|
38
|
|
|
class TestEntityFixture extends AbstractEntityFixtureLoader |
39
|
|
|
{ |
40
|
|
|
|
41
|
|
|
} |
42
|
|
|
'; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @test |
46
|
|
|
*/ |
47
|
|
|
public function itCanCreateANewEntityFixture() |
48
|
|
|
{ |
49
|
|
|
$newObjectFqn = 'EdmondsCommerce\\DoctrineStaticMeta\\Entities\\TestEntityFixture'; |
50
|
|
|
$file = $this->getCreator()->createTargetFileObject($newObjectFqn)->getTargetFile(); |
51
|
|
|
$expected = self::FIXTURE; |
52
|
|
|
$actual = $file->getContents(); |
53
|
|
|
self::assertSame($expected, $actual); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
private function getCreator(): EntityFixtureCreator |
57
|
|
|
{ |
58
|
|
|
$namespaceHelper = new NamespaceHelper(); |
59
|
|
|
$config = new Config(ConfigTest::SERVER); |
60
|
|
|
|
61
|
|
|
return new EntityFixtureCreator( |
62
|
|
|
new FileFactory($namespaceHelper, $config), |
63
|
|
|
$namespaceHelper, |
64
|
|
|
new Writer(), |
65
|
|
|
$config, |
66
|
|
|
new FindReplaceFactory() |
67
|
|
|
); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @test |
72
|
|
|
*/ |
73
|
|
|
public function itCanCreateANewEntityFixtureFromEntityFqn() |
74
|
|
|
{ |
75
|
|
|
$entityFqn = 'EdmondsCommerce\\DoctrineStaticMeta\\Entities\\TestEntity'; |
76
|
|
|
$file = $this->getCreator() |
77
|
|
|
->setNewObjectFqnFromEntityFqn($entityFqn) |
78
|
|
|
->createTargetFileObject() |
79
|
|
|
->getTargetFile(); |
80
|
|
|
$expected = self::FIXTURE; |
81
|
|
|
$actual = $file->getContents(); |
82
|
|
|
self::assertSame($expected, $actual); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @test |
87
|
|
|
*/ |
88
|
|
|
public function itCanCreateADeeplyNamespacedNewEntityFixture() |
89
|
|
|
{ |
90
|
|
|
$newObjectFqn = 'EdmondsCommerce\\DoctrineStaticMeta\\Entities\\Deeply\\Nested\\Entities\\TestEntityFixture'; |
91
|
|
|
$file = $this->getCreator()->createTargetFileObject($newObjectFqn)->getTargetFile(); |
92
|
|
|
$expected = self::NESTED_FIXTURE; |
93
|
|
|
$actual = $file->getContents(); |
94
|
|
|
self::assertSame($expected, $actual); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @test |
99
|
|
|
*/ |
100
|
|
|
public function itCanCreateADeeplyNamespacedNewEntityFixtureFromEntityFqn() |
101
|
|
|
{ |
102
|
|
|
$entityFqn = 'EdmondsCommerce\\DoctrineStaticMeta\\Entities\\Deeply\\Nested\\Entities\\TestEntity'; |
103
|
|
|
$file = $this->getCreator() |
104
|
|
|
->setNewObjectFqnFromEntityFqn($entityFqn) |
105
|
|
|
->createTargetFileObject() |
106
|
|
|
->getTargetFile(); |
107
|
|
|
$expected = self::NESTED_FIXTURE; |
108
|
|
|
$actual = $file->getContents(); |
109
|
|
|
self::assertSame($expected, $actual); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|