Completed
Pull Request — 5.1 (#2266)
by
unknown
12:07
created

testParseSf3Flow()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Kunstmaan\PagePartBundle\Tests\PagePartConfigurationReader;
4
5
use Codeception\Test\Unit;
6
use Kunstmaan\PagePartBundle\PagePartAdmin\PagePartAdminConfiguratorInterface;
7
use Kunstmaan\PagePartBundle\PagePartConfigurationReader\PagePartConfigurationParser;
8
use Symfony\Component\HttpKernel\KernelInterface;
9
10
class PagePartConfigurationParserTest extends Unit
11
{
12
    public function testParseSf4Flow()
13
    {
14
        $kernel = $this->makeEmpty(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()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
33
    {
34
        $kernel = $this->makeEmpty(KernelInterface::class, [
35
            'locateResource' => __DIR__ . '/Resources/config/pageparts/main.yml',
36
        ]);
37
38
        $pagePartConfigurationParser = new PagePartConfigurationParser($kernel, []);
39
40
        $result = $pagePartConfigurationParser->parse('MyWebsiteBundle:main');
41
        $this->assertInstanceOf(PagePartAdminConfiguratorInterface::class, $result);
42
        $this->assertEquals('Main content', $result->getName());
43
    }
44
45
    public function testPresetExtendsBundle()
46
    {
47
        $kernel = $this->makeEmpty(KernelInterface::class);
48
        $pagePartConfigurationParser = new PagePartConfigurationParser($kernel, [
49
            'foo' => [
50
                'name' => 'Foo content',
51
                'context' => 'foo',
52
                'extends' => 'main',
53
                'types' => [
54
                    ['name' => 'FooBar', 'class' => 'Foo\BarPagePart'],
55
                    ['name' => 'Foo', 'class' => 'FooPagePart'],
56
                    ['name' => 'Bar', 'class' => 'BarPagePart'],
57
                ],
58
            ],
59
            'main' => [
60
                'name' => 'Main content',
61
                'context' => 'main',
62
                'types' => [
63
                    ['name' => 'Header', 'class' => 'HeaderPagePart'],
64
                ],
65
            ],
66
        ]
67
        );
68
69
        $value = $pagePartConfigurationParser->parse('foo');
70
71
        $this->assertCount(4, $value->getPossiblePagePartTypes());
72
    }
73
74
    /**
75
     * @expectedException \RuntimeException
76
     */
77
    public function testCircularReferenceIsDetected()
78
    {
79
        $kernel = $this->makeEmpty(KernelInterface::class);
80
81
        $parser = new PagePartConfigurationParser($kernel, [
82
            'foo' => [
83
                'name' => 'Foo preset',
84
                'extends' => 'bar',
85
            ],
86
            'bar' => [
87
                'name' => 'Bar preset',
88
                'extends' => 'baz',
89
            ],
90
            'baz' => [
91
                'name' => 'Baz preset',
92
                'extends' => 'foo',
93
            ],
94
        ]);
95
96
        $parser->parse('foo');
97
    }
98
}
99