Completed
Push — master ( e62fa2...4391c3 )
by Kristof
133:20 queued 117:59
created

SeoBundle/Tests/unit/Twig/TwigExtensionTests.php (3 issues)

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\SeoBundle\Tests\Entity;
4
5
use Kunstmaan\SeoBundle\Entity\Seo;
6
use Kunstmaan\SeoBundle\Twig\SeoTwigExtension;
7
use PHPUnit_Framework_TestCase;
8
9
/**
10
 * Class TwigExtensionTests
11
 */
12
class TwigExtensionTests extends PHPUnit_Framework_TestCase
13
{
14
    protected $emMock;
15
16
    protected $entityMock;
17
18
    protected $seoRepoMock;
19
20
    /**
21
     * Sets up the fixture, for example, opens a network connection.
22
     * This method is called before a test is executed.
23
     */
24
    protected function setUp()
25
    {
26
        $this->emMock = $this->createMock('\Doctrine\ORM\EntityManager',
27
            array('getRepository', 'getClassMetadata', 'persist', 'flush'), array(), '', false);
0 ignored issues
show
The call to TwigExtensionTests::createMock() has too many arguments starting with array('getRepository', '...a', 'persist', 'flush').

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
28
    }
29
30
    /**
31
     * testShouldReturnNameForEntityWhenNoSEO
32
     */
33 View Code Duplication
    public function testShouldReturnNameForEntityWhenNoSEO()
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...
34
    {
35
        $name = 'OK';
36
37
        $this->entityWithName($name);
38
        $this->noSeoFound();
39
40
        $object = new SeoTwigExtension($this->emMock);
41
42
        $result = $object->getTitleFor($this->entityMock);
43
44
        $this->assertEquals($name, $result);
45
    }
46
47
    /**
48
     * testShouldReturnNameForEntityWhenSEOWithTitleFound
49
     */
50 View Code Duplication
    public function testShouldReturnNameForEntityWhenSEOWithTitleFound()
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...
51
    {
52
        $nokName = 'NOK';
53
        $name = 'OK';
54
55
        $this->entityWithName($nokName);
56
        $this->seoFoundWithTitle($name);
57
58
        $object = new SeoTwigExtension($this->emMock);
59
60
        $result = $object->getTitleFor($this->entityMock);
61
62
        $this->assertEquals($name, $result);
63
    }
64
65
    /**
66
     * @param string $name
67
     */
68
    protected function entityWithName($name)
69
    {
70
        $this->entityMock = $this->createMock('Kunstmaan\NodeBundle\Entity\AbstractPage');
71
        $this->entityMock->expects($this->once())->method('getTitle')->will($this->returnValue($name));
72
    }
73
74
    /**
75
     * NoSeoFound
76
     */
77
    protected function noSeoFound()
78
    {
79
        $this->ensureSeoRepoMock();
80
        $this->seoRepoMock->expects($this->once())
81
            ->method('findFor')
82
            ->will($this->returnValue(null));
83
84
        $this->wireUpSeoRepo();
85
    }
86
87
    /**
88
     * ensureSeoRepoMock
89
     */
90
    protected function ensureSeoRepoMock()
91
    {
92
        if (is_null($this->seoRepoMock)) {
93
            $this->seoRepoMock = $this->createMock('Kunstmaan\SeoBundle\Repository\SeoRepository', array(), array(), '', false);
94
        }
95
    }
96
97
    /**
98
     * wireUpSeoRepo
99
     */
100
    protected function wireUpSeoRepo()
101
    {
102
        $this->emMock->expects($this->once())
103
            ->method('getRepository')
104
            ->with($this->equalTo('KunstmaanSeoBundle:Seo'))
105
            ->will($this->returnValue($this->seoRepoMock));
106
    }
107
108
    /**
109
     * @param string $title
110
     */
111
    protected function seoFoundWithTitle($title)
112
    {
113
        $this->ensureSeoRepoMock();
114
115
        $seoMock = new Seo();
116
        $seoMock->setRef($this->entityMock);
117
        $seoMock->setMetaTitle($title);
118
119
        $this->seoRepoMock->expects($this->once())
120
            ->method('findFor')
121
            ->will($this->returnValue($seoMock));
122
123
        $this->wireUpSeoRepo();
124
    }
125
}
126