testRenderWillRetrieveCorrectRegions()   A
last analyzed

Complexity

Conditions 5
Paths 6

Size

Total Lines 56
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
cc 5
eloc 34
nc 6
nop 4
dl 0
loc 56
ccs 0
cts 43
cp 0
crap 30
rs 9.0648
c 0
b 0
f 0

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
 * @author Gerard van Helden <[email protected]>
4
 * @copyright Zicht Online <http://zicht.nl>
5
 */
6
7
namespace Zicht\Bundle\PageBundle\Test\Integration;
8
9
use Zicht\Bundle\PageBundle\Model\ContentItemMatrix;
10
11
/**
12
 * Class ContentItemMatrixTest
13
 *
14
 * @package Zicht\Bundle\PageBundle\Test\Integration
15
 */
16
class ContentItemMatrixTest extends AbstractPageTest
17
{
18
    /**
19
     * Testing whether the regions are correct
20
     *
21
     * @param string $pageTypeName
22
     * @param string $pageClassName
23
     * @param null $region
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $region is correct as it would always require null to be passed?
Loading history...
24
     * @param null $contentItemClassName
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $contentItemClassName is correct as it would always require null to be passed?
Loading history...
25
     * @dataProvider contentItemMatrix
26
     */
27
    public function testRenderWillRetrieveCorrectRegions($pageTypeName, $pageClassName, $region = null, $contentItemClassName = null)
0 ignored issues
show
Unused Code introduced by
The parameter $pageTypeName is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

27
    public function testRenderWillRetrieveCorrectRegions(/** @scrutinizer ignore-unused */ $pageTypeName, $pageClassName, $region = null, $contentItemClassName = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
28
    {
29
        $this->markTestSkipped();
30
31
32
        if (null === $contentItemClassName || null === $region) {
33
            $this->markTestSkipped("{$pageClassName} has no content item matrix");
34
        } elseif (!class_exists($contentItemClassName)) {
35
            $this->fail("{$contentItemClassName} does not exist");
36
        }
37
38
        /** @var \Zicht\Bundle\PageBundle\Model\PageInterface $p */
39
        $realPage = new $pageClassName;
40
41
        $recorded = array();
42
43
        $pageUnderTest = clone $realPage;
44
45
        $contentItem = new $contentItemClassName;
46
        $contentItem->setRegion($region);
47
        $pageUnderTest->addContentItem($contentItem);
48
49
        $mockPage = $this->getMock($pageClassName, array('getContentItems', 'getTemplateName'));
50
        $mockPage
51
            ->expects($this->atLeastOnce())
52
            ->method('getContentItems')
53
            ->will(
54
                $this->returnCallback(
55
                    function () use (&$recorded, $pageUnderTest, $region) {
56
                        $args = func_get_args();
57
                        $recorded[]= $args;
58
                        $ret = call_user_func_array(array($pageUnderTest, 'getContentItems'), $args);
59
                        return $ret;
60
                    }
61
                )
62
            );
63
64
        $mockPage->expects($this->any())
65
            ->method('getTemplateName')
66
            ->will(
67
                $this->returnCallback(
68
                    function () use ($pageUnderTest) {
69
                        return $pageUnderTest->getTemplateName();
70
                    }
71
                )
72
            );
73
74
        /** @var \Zicht\Bundle\PageBundle\Entity\ContentItem $item */
75
        $pageController = $this->createPageController();
76
        $pageController->renderPage($mockPage)->getContent();
77
78
        $called = array();
79
        foreach ($recorded as $calls) {
80
            $called[]= $calls[0];
81
        }
82
        $this->assertContains($region, $called);
83
    }
84
85
86
    /**
87
     * Content item matrix
88
     *
89
     * @return array
90
     */
91
    public function contentItemMatrix()
92
    {
93
        $pageManager = $this->createPageManager();
94
        $mappings = $pageManager->getMappings();
95
96
        $ret = array();
97
        foreach ($mappings[$pageManager->getPageClass()] as $name => $pageClassName) {
98
            $realPage = new $pageClassName;
99
            $matrix = $realPage->getContentItemMatrix();
100
101
            /** @var ContentItemMatrix $matrix */
102
            if (!$matrix) {
103
                $ret[]= array($name, $pageClassName);
104
                continue;
105
            }
106
107
            foreach ($matrix->getTypes() as $contentItemClassName) {
108
                foreach ($matrix->getRegions($contentItemClassName) as $region) {
109
                    $ret[]= array($name, $pageClassName, $region, $contentItemClassName);
110
                }
111
            }
112
        }
113
114
        return $ret;
115
    }
116
}
117