Completed
Push — l10n_master ( 6cb695...818918 )
by Kunstmaan
50:17 queued 35:37
created

PagePartConfigurationParserTest.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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()
0 ignored issues
show
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->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
    /**
74
     * @expectedException \RuntimeException
75
     */
76
    public function testCircularReferenceIsDetected()
77
    {
78
        $kernel = $this->createMock(KernelInterface::class);
79
80
        $parser = new PagePartConfigurationParser($kernel, [
81
            'foo' => [
82
                'name' => 'Foo preset',
83
                'extends' => 'bar',
84
            ],
85
            'bar' => [
86
                'name' => 'Bar preset',
87
                'extends' => 'baz',
88
            ],
89
            'baz' => [
90
                'name' => 'Baz preset',
91
                'extends' => 'foo',
92
            ],
93
        ]);
94
95
        $parser->parse('foo');
96
    }
97
}
98