1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kunstmaan\PagePartBundle\Tests\PagePartConfigurationReader; |
4
|
|
|
|
5
|
|
|
use Kunstmaan\PagePartBundle\PagePartAdmin\PagePartAdminConfiguratorInterface; |
6
|
|
|
use Kunstmaan\PagePartBundle\PagePartConfigurationReader\PagePartConfigurationParser; |
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use Symfony\Component\HttpKernel\KernelInterface; |
9
|
|
|
|
10
|
|
|
class PagePartConfigurationParserTest extends TestCase |
11
|
|
|
{ |
12
|
|
|
public function testParseSf4Flow() |
13
|
|
|
{ |
14
|
|
|
$kernel = $this->createMock(KernelInterface::class); |
15
|
|
|
$pagePartConfigurationParser = new PagePartConfigurationParser($kernel, [ |
16
|
|
|
'main' => [ |
17
|
|
|
'name' => 'Main content', |
18
|
|
|
'context' => 'main', |
19
|
|
|
'types' => [ |
20
|
|
|
['name' => 'FooBar', 'class' => 'Foo\BarPagePart'], |
21
|
|
|
['name' => 'Foo', 'class' => 'FooPagePart'], |
22
|
|
|
['name' => 'Bar', 'class' => 'BarPagePart'], |
23
|
|
|
], |
24
|
|
|
], |
25
|
|
|
]); |
26
|
|
|
|
27
|
|
|
$result = $pagePartConfigurationParser->parse('main'); |
28
|
|
|
$this->assertInstanceOf(PagePartAdminConfiguratorInterface::class, $result); |
29
|
|
|
$this->assertEquals('Main content', $result->getName()); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
View Code Duplication |
public function testParseSf3Flow() |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
$kernel = $this->createMock(KernelInterface::class); |
35
|
|
|
$kernel->method('locateResource')->willReturn(__DIR__ . '/Resources/config/pageparts/main.yml'); |
36
|
|
|
|
37
|
|
|
$pagePartConfigurationParser = new PagePartConfigurationParser($kernel, []); |
38
|
|
|
|
39
|
|
|
$result = $pagePartConfigurationParser->parse('MyWebsiteBundle:main'); |
40
|
|
|
$this->assertInstanceOf(PagePartAdminConfiguratorInterface::class, $result); |
41
|
|
|
$this->assertEquals('Main content', $result->getName()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testPresetExtendsBundle() |
45
|
|
|
{ |
46
|
|
|
$kernel = $this->createMock(KernelInterface::class); |
47
|
|
|
$pagePartConfigurationParser = new PagePartConfigurationParser($kernel, [ |
48
|
|
|
'foo' => [ |
49
|
|
|
'name' => 'Foo content', |
50
|
|
|
'context' => 'foo', |
51
|
|
|
'extends' => 'main', |
52
|
|
|
'types' => [ |
53
|
|
|
['name' => 'FooBar', 'class' => 'Foo\BarPagePart'], |
54
|
|
|
['name' => 'Foo', 'class' => 'FooPagePart'], |
55
|
|
|
['name' => 'Bar', 'class' => 'BarPagePart'], |
56
|
|
|
], |
57
|
|
|
], |
58
|
|
|
'main' => [ |
59
|
|
|
'name' => 'Main content', |
60
|
|
|
'context' => 'main', |
61
|
|
|
'types' => [ |
62
|
|
|
['name' => 'Header', 'class' => 'HeaderPagePart'], |
63
|
|
|
], |
64
|
|
|
], |
65
|
|
|
] |
66
|
|
|
); |
67
|
|
|
|
68
|
|
|
$value = $pagePartConfigurationParser->parse('foo'); |
69
|
|
|
|
70
|
|
|
$this->assertCount(4, $value->getPossiblePagePartTypes()); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function testCircularReferenceIsDetected() |
74
|
|
|
{ |
75
|
|
|
$this->expectException(\RuntimeException::class); |
76
|
|
|
$kernel = $this->createMock(KernelInterface::class); |
77
|
|
|
|
78
|
|
|
$parser = new PagePartConfigurationParser($kernel, [ |
79
|
|
|
'foo' => [ |
80
|
|
|
'name' => 'Foo preset', |
81
|
|
|
'extends' => 'bar', |
82
|
|
|
], |
83
|
|
|
'bar' => [ |
84
|
|
|
'name' => 'Bar preset', |
85
|
|
|
'extends' => 'baz', |
86
|
|
|
], |
87
|
|
|
'baz' => [ |
88
|
|
|
'name' => 'Baz preset', |
89
|
|
|
'extends' => 'foo', |
90
|
|
|
], |
91
|
|
|
]); |
92
|
|
|
|
93
|
|
|
$parser->parse('foo'); |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.