GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#9)
by Mario
07:30
created

testInstanceOfTwigExtensionInterface()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Netgen\Bundle\OpenGraphBundle\Tests\Templating\Twig\Extension;
4
5
use eZ\Publish\Core\Repository\Values\Content\Content;
6
use Netgen\Bundle\OpenGraphBundle\MetaTag\Collector;
7
use Netgen\Bundle\OpenGraphBundle\MetaTag\Item;
8
use Netgen\Bundle\OpenGraphBundle\MetaTag\Renderer;
9
use Netgen\Bundle\OpenGraphBundle\Templating\Twig\Extension\NetgenOpenGraphRuntime;
10
use PHPUnit\Framework\TestCase;
11
use Psr\Log\NullLogger;
12
13
class NetgenOpenGraphRuntimeTest extends TestCase
14
{
15
    /**
16
     * @var \Netgen\Bundle\OpenGraphBundle\Templating\Twig\Extension\NetgenOpenGraphRuntime
17
     */
18
    protected $runtime;
19
20
    /**
21
     * @var \PHPUnit_Framework_MockObject_MockObject
22
     */
23
    protected $collector;
24
25
    /**
26
     * @var \PHPUnit_Framework_MockObject_MockObject
27
     */
28
    protected $renderer;
29
30
    /**
31
     * @var \PHPUnit_Framework_MockObject_MockObject
32
     */
33
    protected $logger;
34
35 View Code Duplication
    public function setUp()
0 ignored issues
show
Duplication introduced by
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...
36
    {
37
        $this->collector = $this->getMockBuilder(Collector::class)
38
            ->disableOriginalConstructor()
39
            ->setMethods(array('collect'))
40
            ->getMock();
41
42
        $this->renderer = $this->getMockBuilder(Renderer::class)
43
            ->disableOriginalConstructor()
44
            ->setMethods(array('render'))
45
            ->getMock();
46
47
        $this->logger = $this->getMockBuilder(NullLogger::class)
48
            ->disableOriginalConstructor()
49
            ->setMethods(array('error'))
50
            ->getMock();
51
52
        $this->runtime = new NetgenOpenGraphRuntime($this->collector, $this->renderer, $this->logger);
0 ignored issues
show
Documentation introduced by
$this->collector is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Netgen\Bundle\Ope...Tag\CollectorInterface>.

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...
Documentation introduced by
$this->renderer is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Netgen\Bundle\Ope...aTag\RendererInterface>.

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...
Documentation introduced by
$this->logger is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a null|object<Psr\Log\LoggerInterface>.

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...
53
    }
54
55
    public function testInstanceOfTwigExtensionInterface()
56
    {
57
        $this->assertInstanceOf(NetgenOpenGraphRuntime::class, $this->runtime);
58
    }
59
60
    /**
61
     * @doesNotPerformAssertions
62
     */
63
    public function testSetThrowExceptions()
64
    {
65
        $this->runtime->setThrowExceptions(true);
66
    }
67
68
    public function testGetOpenGraphTags()
69
    {
70
        $items = array(
71
            new Item('tag1', 'some_value'),
72
        );
73
74
        $this->collector->expects($this->once())
75
            ->method('collect')
76
            ->willReturn($items);
77
78
        $result = $this->runtime->getOpenGraphTags(new Content());
79
80
        $this->assertEquals($items, $result);
81
    }
82
83
    /**
84
     * @expectedException \Exception
85
     */
86
    public function testGetOpenGraphTagsWithThrowedException()
87
    {
88
        $this->collector->expects($this->once())
89
            ->method('collect')
90
            ->willThrowException(new \Exception());
91
92
        $this->runtime->setThrowExceptions(true);
93
        $this->runtime->getOpenGraphTags(new Content());
94
    }
95
96 View Code Duplication
    public function testGetOpenGraphTagsWithLoggedException()
0 ignored issues
show
Duplication introduced by
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...
97
    {
98
        $this->collector->expects($this->once())
99
            ->method('collect')
100
            ->willThrowException(new \Exception());
101
102
        $this->logger->expects($this->once())
103
            ->method('error');
104
105
        $this->runtime->setThrowExceptions(false);
106
        $this->runtime->getOpenGraphTags(new Content());
107
    }
108
109
    public function testRenderOpenGraphTags()
110
    {
111
        $items = array(
112
            new Item('tag1', 'some_value'),
113
        );
114
115
        $resultString = '<meta property="tag1" content="some_value" />';
116
117
        $this->collector->expects($this->once())
118
            ->method('collect')
119
            ->willReturn($items);
120
121
        $this->renderer->expects($this->once())
122
            ->method('render')
123
            ->willReturn($resultString);
124
125
        $result = $this->runtime->renderOpenGraphTags(new Content());
126
127
        $this->assertEquals($resultString, $result);
128
    }
129
130
    /**
131
     * @expectedException \Exception
132
     */
133 View Code Duplication
    public function testRenderOpenGraphTagsWithThrowedException()
0 ignored issues
show
Duplication introduced by
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...
134
    {
135
        $this->collector->expects($this->once())
136
            ->method('collect')
137
            ->willReturn(array());
138
139
        $this->renderer->expects($this->once())
140
            ->method('render')
141
            ->willThrowException(new \Exception());
142
143
        $this->runtime->setThrowExceptions(true);
144
        $this->runtime->renderOpenGraphTags(new Content());
145
    }
146
147
    public function testRenderOpenGraphTagsWithLoggedException()
148
    {
149
        $this->collector->expects($this->once())
150
            ->method('collect')
151
            ->willReturn(array());
152
153
        $this->renderer->expects($this->once())
154
            ->method('render')
155
            ->willThrowException(new \Exception());
156
157
        $this->logger->expects($this->once())
158
            ->method('error');
159
160
        $this->runtime->setThrowExceptions(false);
161
        $this->runtime->renderOpenGraphTags(new Content());
162
    }
163
}
164