testParseSf3Flow()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
dl 11
loc 11
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 0
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, [
0 ignored issues
show
Documentation introduced by
$kernel is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...Kernel\KernelInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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->createMock(KernelInterface::class);
35
        $kernel->method('locateResource')->willReturn(__DIR__ . '/Resources/config/pageparts/main.yml');
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<PHPUnit\Framework\MockObject\MockObject>.

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.

Loading history...
36
37
        $pagePartConfigurationParser = new PagePartConfigurationParser($kernel, []);
0 ignored issues
show
Documentation introduced by
$kernel is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...Kernel\KernelInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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, [
0 ignored issues
show
Documentation introduced by
$kernel is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...Kernel\KernelInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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());
0 ignored issues
show
Documentation introduced by
$value->getPossiblePagePartTypes() is of type array, but the function expects a object<Countable>|object...nit\Framework\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
71
    }
72
73
    public function testCircularReferenceIsDetected()
74
    {
75
        $this->expectException(\RuntimeException::class);
76
        $kernel = $this->createMock(KernelInterface::class);
77
78
        $parser = new PagePartConfigurationParser($kernel, [
0 ignored issues
show
Documentation introduced by
$kernel is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...Kernel\KernelInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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