Completed
Push — master ( 1de9b7...830752 )
by Kristof
38:46 queued 24:09
created

SeoBundle/Tests/unit/Twig/TwigExtensionTests.php (6 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 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()
34
    {
35
        $name = 'OK';
36
37
        $this->entityWithName($name);
38
        $this->noSeoFound();
39
40
        $object = new SeoTwigExtension($this->emMock);
0 ignored issues
show
$this->emMock is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ORM\EntityManager>.

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...
41
42
        $result = $object->getTitleFor($this->entityMock);
0 ignored issues
show
$this->entityMock is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Kunstmaan\NodeBundle\Entity\AbstractPage>.

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...
43
44
        $this->assertEquals($name, $result);
45
    }
46
47
    /**
48
     * testShouldReturnNameForEntityWhenSEOWithTitleFound
49
     */
50 View Code Duplication
    public function testShouldReturnNameForEntityWhenSEOWithTitleFound()
51
    {
52
        $nokName = 'NOK';
53
        $name = 'OK';
54
55
        $this->entityWithName($nokName);
56
        $this->seoFoundWithTitle($name);
57
58
        $object = new SeoTwigExtension($this->emMock);
0 ignored issues
show
$this->emMock is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ORM\EntityManager>.

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...
59
60
        $result = $object->getTitleFor($this->entityMock);
0 ignored issues
show
$this->entityMock is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Kunstmaan\NodeBundle\Entity\AbstractPage>.

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...
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);
0 ignored issues
show
$this->entityMock is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Kunstmaan\AdminBu...\Entity\AbstractEntity>.

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...
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