Completed
Push — EZP-31644 ( d0f8f8...1e4423 )
by
unknown
16:33
created

InlineFragmentRendererTest::testRendererControllerReferenceWithCompoundMatcher()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 54

Duplication

Lines 9
Ratio 16.67 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 9
loc 54
rs 9.0036
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A InlineFragmentRendererTest::getRenderer() 0 4 1
A InlineFragmentRendererTest::setAdditionalAsserts() 0 7 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
namespace eZ\Bundle\EzPublishCoreBundle\Tests\Fragment;
8
9
use eZ\Bundle\EzPublishCoreBundle\Fragment\InlineFragmentRenderer;
10
use eZ\Publish\Core\MVC\Symfony\SiteAccess;
11
use Symfony\Component\HttpFoundation\Request;
12
use Symfony\Component\HttpKernel\Controller\ControllerReference;
13
use Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface;
14
15
class InlineFragmentRendererTest extends DecoratedFragmentRendererTest
16
{
17
    public function testRendererControllerReference()
18
    {
19
        $reference = new ControllerReference('FooBundle:bar:baz');
20
        $matcher = new SiteAccess\Matcher\HostElement(1);
21
        $siteAccess = new SiteAccess(
22
            'test',
23
            'test',
24
            $matcher
25
        );
26
        $request = new Request();
27
        $request->attributes->set('siteaccess', $siteAccess);
28
        $request->attributes->set('semanticPathinfo', '/foo/bar');
29
        $request->attributes->set('viewParametersString', '/(foo)/bar');
30
        $options = ['foo' => 'bar'];
31
        $expectedReturn = '/_fragment?foo=bar';
32
        $this->innerRenderer
33
            ->expects($this->once())
34
            ->method('render')
35
            ->with($reference, $request, $options)
36
            ->will($this->returnValue($expectedReturn));
37
38
        $renderer = new InlineFragmentRenderer($this->innerRenderer);
39
        $this->assertSame($expectedReturn, $renderer->render($reference, $request, $options));
40
        $this->assertArrayHasKey('serialized_siteaccess', $reference->attributes);
41
        $serializedSiteAccess = json_encode($siteAccess);
42
        $this->assertSame($serializedSiteAccess, $reference->attributes['serialized_siteaccess']);
43
        $this->assertTrue(isset($reference->attributes['serialized_siteaccess_matcher']));
44
        $this->assertSame(
45
            $this->getSerializer()->serialize(
46
                $siteAccess->matcher,
47
                'json'
48
            ),
49
            $reference->attributes['serialized_siteaccess_matcher']
50
        );
51
        $this->assertTrue(isset($reference->attributes['semanticPathinfo']));
52
        $this->assertSame('/foo/bar', $reference->attributes['semanticPathinfo']);
53
        $this->assertTrue(isset($reference->attributes['viewParametersString']));
54
        $this->assertSame('/(foo)/bar', $reference->attributes['viewParametersString']);
55
    }
56
57
    public function getRequest(SiteAccess $siteAccess): Request
58
    {
59
        $request = new Request();
60
        $request->attributes->set('siteaccess', $siteAccess);
61
        $request->attributes->set('semanticPathinfo', '/foo/bar');
62
        $request->attributes->set('viewParametersString', '/(foo)/bar');
63
64
        return $request;
65
    }
66
67
    public function getRenderer(): FragmentRendererInterface
68
    {
69
        return new InlineFragmentRenderer($this->innerRenderer);
70
    }
71
72
    public function setAdditionalAsserts(ControllerReference $reference): void
73
    {
74
        $this->assertTrue(isset($reference->attributes['semanticPathinfo']));
75
        $this->assertSame('/foo/bar', $reference->attributes['semanticPathinfo']);
76
        $this->assertTrue(isset($reference->attributes['viewParametersString']));
77
        $this->assertSame('/(foo)/bar', $reference->attributes['viewParametersString']);
78
    }
79
}
80