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
01:45
created

ImageTest   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 223
Duplicated Lines 25.11 %

Coupling/Cohesion

Components 1
Dependencies 12

Importance

Changes 0
Metric Value
wmc 11
c 0
b 0
f 0
lcom 1
cbo 12
dl 56
loc 223
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
B setUp() 0 34 1
A testInstanceOfHandlerInterface() 0 4 1
A testGettingTagsWithoutFieldIdentifier() 0 4 1
A testGettingTagsWithNonExistentField() 0 8 1
A testGettingTagsWithUnsupportedField() 0 8 1
A testGettingTagsWithEmptyField() 0 12 1
A testGettingTagsWithExceptionThrownByVariationHandler() 0 17 1
B testGettingTags() 0 27 1
B testGettingTagsWithVariationServiceThrowsInvalidVariationException() 28 28 1
B testGettingTagsWithVariationServiceThrowsSourceImageNotFoundException() 28 28 1
A testGettingTagsWithMultipleArgumentsInArray() 0 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Netgen\Bundle\OpenGraphBundle\Tests\Handler\FieldType;
4
5
use eZ\Bundle\EzPublishCoreBundle\Imagine\AliasGenerator;
6
use eZ\Publish\API\Repository\Exceptions\InvalidVariationException;
7
use eZ\Publish\API\Repository\Values\Content\Field;
8
use eZ\Publish\Core\FieldType\Image\Value;
9
use eZ\Publish\Core\Helper\FieldHelper;
10
use eZ\Publish\Core\Helper\TranslationHelper;
11
use eZ\Publish\Core\MVC\Exception\SourceImageNotFoundException;
12
use eZ\Publish\Core\Repository\Values\Content\Content;
13
use eZ\Publish\Core\Repository\Values\Content\VersionInfo;
14
use eZ\Publish\SPI\Variation\Values\Variation;
15
use Netgen\Bundle\OpenGraphBundle\Handler\FieldType\Image;
16
use Netgen\Bundle\OpenGraphBundle\Handler\HandlerInterface;
17
use Psr\Log\NullLogger;
18
use Symfony\Component\HttpFoundation\Request;
19
use Symfony\Component\HttpFoundation\RequestStack;
20
21
class ImageTest extends HandlerBaseTest
22
{
23
    /**
24
     * @var Image
25
     */
26
    protected $image;
27
28
    /**
29
     * @var \PHPUnit_Framework_MockObject_MockObject
30
     */
31
    protected $variationHandler;
32
33
    /**
34
     * @var \PHPUnit_Framework_MockObject_MockObject
35
     */
36
    protected $requestStack;
37
38
    /**
39
     * @var \PHPUnit_Framework_MockObject_MockObject
40
     */
41
    protected $logger;
42
43
    public function setUp()
44
    {
45
        $this->fieldHelper = $this->getMockBuilder(FieldHelper::class)
46
            ->disableOriginalConstructor()
47
            ->setMethods(array('isFieldEmpty'))
48
            ->getMock();
49
50
        $this->translationHelper = $this->getMockBuilder(TranslationHelper::class)
51
            ->disableOriginalConstructor()
52
            ->setMethods(array('getTranslatedField'))
53
            ->getMock();
54
55
        $this->content = new Content(array('versionInfo' => new VersionInfo()));
0 ignored issues
show
Documentation Bug introduced by
It seems like new \eZ\Publish\Core\Rep...Content\VersionInfo())) of type object<eZ\Publish\Core\R...Values\Content\Content> is incompatible with the declared type object<PHPUnit_Framework_MockObject_MockObject> of property $content.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
56
57
        $this->variationHandler = $this->getMockBuilder(AliasGenerator::class)
58
            ->disableOriginalConstructor()
59
            ->setMethods(array('getVariation'))
60
            ->getMock();
61
62
        $this->requestStack = $this->getMockBuilder(RequestStack::class)
63
            ->disableOriginalConstructor()
64
            ->setMethods(array('getCurrentRequest'))
65
            ->getMock();
66
67
        $this->logger = $this->getMockBuilder(NullLogger::class)
68
            ->disableOriginalConstructor()
69
            ->setMethods(array())
70
            ->getMock();
71
72
        $this->image = new Image($this->fieldHelper, $this->translationHelper, $this->variationHandler, $this->requestStack, $this->logger);
73
        $this->image->setContent($this->content);
74
75
        $this->field = new Field(array('value' => new Value()));
76
    }
77
78
    public function testInstanceOfHandlerInterface()
79
    {
80
        $this->assertInstanceOf(HandlerInterface::class, $this->image);
81
    }
82
83
    /**
84
     * @expectedException \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException
85
     * @expectedExceptionMessage Argument '$params[0]' is invalid: Field type handlers require at least a field identifier.
86
     */
87
    public function testGettingTagsWithoutFieldIdentifier()
88
    {
89
        $this->image->getMetaTags('some_tag', array());
90
    }
91
92
    /**
93
     * @expectedException \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException
94
     * @expectedExceptionMessage Argument '$params[0]' is invalid: Field 'some_value' does not exist in content.
95
     */
96
    public function testGettingTagsWithNonExistentField()
97
    {
98
        $this->translationHelper->expects($this->once())
99
            ->method('getTranslatedField')
100
            ->willReturn(null);
101
102
        $this->image->getMetaTags('some_tag', array('some_value'));
103
    }
104
105
    /**
106
     * @expectedException \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException
107
     * @expectedExceptionMessage Argument '$params[0]' is invalid: Netgen\Bundle\OpenGraphBundle\Handler\FieldType\Image field type handler does not support field with identifier ''.
108
     */
109
    public function testGettingTagsWithUnsupportedField()
110
    {
111
        $this->translationHelper->expects($this->once())
112
            ->method('getTranslatedField')
113
            ->willReturn(new Field());
114
115
        $this->image->getMetaTags('some_tag', array('some_value'));
116
    }
117
118
    public function testGettingTagsWithEmptyField()
119
    {
120
        $this->translationHelper->expects($this->once())
121
            ->method('getTranslatedField')
122
            ->willReturn($this->field);
123
124
        $this->fieldHelper->expects($this->once())
125
            ->method('isFieldEmpty')
126
            ->willReturn(true);
127
128
        $this->image->getMetaTags('some_tag', array('some_value'));
129
    }
130
131
    public function testGettingTagsWithExceptionThrownByVariationHandler()
132
    {
133
        $this->translationHelper->expects($this->once())
134
            ->method('getTranslatedField')
135
            ->willReturn($this->field);
136
137
        $request = $this->getMockBuilder(Request::class)
138
            ->disableOriginalConstructor()
139
            ->setMethods(array())
140
            ->getMock();
141
142
        $this->requestStack->expects($this->once())
143
            ->method('getCurrentRequest')
144
            ->willReturn($request);
145
146
        $this->image->getMetaTags('some_tag', array('some_value', 'some_value_2', 'some_value_3'));
147
    }
148
149
    public function testGettingTags()
150
    {
151
        $this->translationHelper->expects($this->once())
152
            ->method('getTranslatedField')
153
            ->willReturn($this->field);
154
155
        $this->fieldHelper->expects($this->once())
156
            ->method('isFieldEmpty')
157
            ->willReturn(false);
158
159
        $variation = new Variation(array('uri' => '/some/uri'));
160
161
        $this->variationHandler->expects($this->once())
162
            ->method('getVariation')
163
            ->willReturn($variation);
164
165
        $request = $this->getMockBuilder(Request::class)
166
            ->disableOriginalConstructor()
167
            ->setMethods(array())
168
            ->getMock();
169
170
        $this->requestStack->expects($this->exactly(2))
171
            ->method('getCurrentRequest')
172
            ->willReturn($request);
173
174
        $this->image->getMetaTags('some_tag', array('some_value', 'some_value_2', 'some_value_3'));
175
    }
176
177 View Code Duplication
    public function testGettingTagsWithVariationServiceThrowsInvalidVariationException()
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...
178
    {
179
        $this->translationHelper->expects($this->once())
180
            ->method('getTranslatedField')
181
            ->willReturn($this->field);
182
183
        $this->fieldHelper->expects($this->once())
184
            ->method('isFieldEmpty')
185
            ->willReturn(false);
186
187
        $this->variationHandler->expects($this->once())
188
            ->method('getVariation')
189
            ->willThrowException(new InvalidVariationException('name', 'type'));
190
191
        $request = $this->getMockBuilder(Request::class)
192
            ->disableOriginalConstructor()
193
            ->setMethods(array())
194
            ->getMock();
195
196
        $this->requestStack->expects($this->once())
197
            ->method('getCurrentRequest')
198
            ->willReturn($request);
199
200
        $this->logger->expects($this->once())
201
            ->method('error');
202
203
        $this->image->getMetaTags('some_tag', array('some_value', 'some_value_2', 'some_value_3'));
204
    }
205
206 View Code Duplication
    public function testGettingTagsWithVariationServiceThrowsSourceImageNotFoundException()
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...
207
    {
208
        $this->translationHelper->expects($this->once())
209
            ->method('getTranslatedField')
210
            ->willReturn($this->field);
211
212
        $this->fieldHelper->expects($this->once())
213
            ->method('isFieldEmpty')
214
            ->willReturn(false);
215
216
        $this->variationHandler->expects($this->once())
217
            ->method('getVariation')
218
            ->willThrowException(new SourceImageNotFoundException('message'));
219
220
        $request = $this->getMockBuilder(Request::class)
221
            ->disableOriginalConstructor()
222
            ->setMethods(array())
223
            ->getMock();
224
225
        $this->requestStack->expects($this->once())
226
            ->method('getCurrentRequest')
227
            ->willReturn($request);
228
229
        $this->logger->expects($this->once())
230
            ->method('error');
231
232
        $this->image->getMetaTags('some_tag', array('some_value', 'some_value_2', 'some_value_3'));
233
    }
234
235
    public function testGettingTagsWithMultipleArgumentsInArray()
236
    {
237
        $this->translationHelper->expects($this->once())
238
            ->method('getTranslatedField')
239
            ->willReturn($this->field);
240
241
        $this->image->getMetaTags('some_tag', array('some_value', 'some_value_2'));
242
    }
243
}
244