Completed
Push — master ( 770316...74fc07 )
by Jeroen
09:08 queued 02:44
created

Kunstmaan/SeoBundle/Tests/unit/Entity/SeoTest.php (2 issues)

mismatching argument types.

Documentation Minor

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 PHPUnit\Framework\TestCase;
7
8
class SeoTest extends TestCase
9
{
10
    /**
11
     * @var Seo
12
     */
13
    protected $object;
14
15
    /**
16
     * Sets up the fixture, for example, opens a network connection.
17
     * This method is called before a test is executed.
18
     */
19
    protected function setUp()
20
    {
21
        $this->object = new Seo();
22
    }
23
24
    public function testGetSetMetaAuthor()
25
    {
26
        $this->object->setMetaAuthor('Author Name');
27
        $this->assertEquals('Author Name', $this->object->getMetaAuthor());
28
    }
29
30
    public function testGetSetMetaDescription()
31
    {
32
        $this->object->setMetaDescription('Meta Description');
33
        $this->assertEquals('Meta Description', $this->object->getMetaDescription());
34
    }
35
36
    public function testGetSetMetaRobots()
37
    {
38
        $this->object->setMetaRobots('noindex, nofollow');
39
        $this->assertEquals('noindex, nofollow', $this->object->getMetaRobots());
40
    }
41
42
    public function testGetSetExtraMetadata()
43
    {
44
        $this->object->setExtraMetadata('Extra Metadata');
45
        $this->assertEquals('Extra Metadata', $this->object->getExtraMetadata());
46
    }
47
48
    public function testGetSetOgDescription()
49
    {
50
        $this->object->setOgDescription('OpenGraph description');
51
        $this->assertEquals('OpenGraph description', $this->object->getOgDescription());
52
    }
53
54
    public function testGetSetOgImageWithImage()
55
    {
56
        $media = $this->createMock('Kunstmaan\MediaBundle\Entity\Media');
57
        $this->object->setOgImage($media);
58
        $this->assertEquals($media, $this->object->getOgImage());
59
    }
60
61
    public function testGetSetOgImageWithNullValue()
62
    {
63
        $this->object->setOgImage(null);
64
        $this->assertEquals(null, $this->object->getOgImage());
65
    }
66
67
    public function testGetSetOgTitle()
68
    {
69
        $this->object->setOgTitle('OpenGraph title');
70
        $this->assertEquals('OpenGraph title', $this->object->getOgTitle());
71
    }
72
73
    public function testGetSetOgType()
74
    {
75
        $this->object->setOgType('website');
76
        $this->assertEquals('website', $this->object->getOgType());
77
    }
78
79
    public function testGetSetTwitterTitle()
80
    {
81
        $this->object->setTwitterTitle('twitter title');
82
        $this->assertEquals('twitter title', $this->object->getTwitterTitle());
83
    }
84
85
    public function testGetSetTwitterDescription()
86
    {
87
        $this->object->setTwitterDescription('twitter description');
88
        $this->assertEquals('twitter description', $this->object->getTwitterDescription());
89
    }
90
91
    public function testGetSetTwitterSite()
92
    {
93
        $this->object->setTwitterSite('@kunstmaan');
94
        $this->assertEquals('@kunstmaan', $this->object->getTwitterSite());
95
    }
96
97
    public function testGetSetTwitterCreator()
98
    {
99
        $this->object->setTwitterCreator('@denbatte');
100
        $this->assertEquals('@denbatte', $this->object->getTwitterCreator());
101
    }
102
103
    public function testGetSetTwitterImageWithImage()
104
    {
105
        $media = $this->createMock('Kunstmaan\MediaBundle\Entity\Media');
106
        $this->object->setTwitterImage($media);
0 ignored issues
show
$media is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Kunstmaan\MediaBundle\Entity\Media>.

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...
107
        $this->assertEquals($media, $this->object->getTwitterImage());
108
    }
109
110
    public function testGetSetTwitterImageWithNullValue()
111
    {
112
        $this->object->setTwitterImage(null);
0 ignored issues
show
null is of type null, but the function expects a object<Kunstmaan\MediaBundle\Entity\Media>.

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...
113
        $this->assertEquals(null, $this->object->getTwitterImage());
114
    }
115
116
    public function testGetDefaultAdminType()
117
    {
118
        $this->assertEquals('Kunstmaan\SeoBundle\Form\SeoType', $this->object->getDefaultAdminType());
119
    }
120
121
    public function testGettersSetters()
122
    {
123
        $this->object->setOgUrl('https://nasa.gov');
124
        $this->object->setMetaTitle('NASA');
125
        $this->object->setOgArticlePublisher('NASA PR dept');
126
        $this->object->setOgArticleSection('Mars');
127
        $this->object->setOgArticleAuthor('delboy1978uk');
128
129
        $this->assertEquals('https://nasa.gov', $this->object->getOgUrl());
130
        $this->assertEquals('NASA', $this->object->getMetaTitle());
131
        $this->assertEquals('NASA PR dept', $this->object->getOgArticlePublisher());
132
        $this->assertEquals('Mars', $this->object->getOgArticleSection());
133
        $this->assertEquals('delboy1978uk', $this->object->getOgArticleAuthor());
134
    }
135
}
136