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
Push — master ( 37c564...56f4ad )
by Mario
01:32
created

TextBlockTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 101
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 8
c 0
b 0
f 0
lcom 1
cbo 7
dl 101
loc 101
rs 10

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\Publish\API\Repository\Values\Content\Field;
6
use eZ\Publish\Core\FieldType\TextBlock\Value;
7
use eZ\Publish\Core\Helper\FieldHelper;
8
use eZ\Publish\Core\Helper\TranslationHelper;
9
use eZ\Publish\Core\Repository\Values\Content\Content;
10
use Netgen\Bundle\OpenGraphBundle\Handler\FieldType\TextBlock;
11
use Netgen\Bundle\OpenGraphBundle\Handler\HandlerInterface;
12
13
class TextBlockTest extends HandlerBaseTest
14
{
15
    /**
16
     * @var TextBlock
17
     */
18
    protected $textBlock;
19
20
    public function setUp()
21
    {
22
        $this->fieldHelper = $this->getMockBuilder(FieldHelper::class)
23
            ->disableOriginalConstructor()
24
            ->setMethods(array('isFieldEmpty'))
25
            ->getMock();
26
27
        $this->translationHelper = $this->getMockBuilder(TranslationHelper::class)
28
            ->disableOriginalConstructor()
29
            ->setMethods(array('getTranslatedField'))
30
            ->getMock();
31
32
        $this->content = $this->getMockBuilder(Content::class)
33
            ->disableOriginalConstructor()
34
            ->setMethods(array())
35
            ->getMock();
36
37
        $this->textBlock = new TextBlock($this->fieldHelper, $this->translationHelper);
38
        $this->textBlock->setContent($this->content);
39
40
        $this->field = new Field(array('value' => new Value()));
41
    }
42
43
    public function testInstanceOfHandlerInterface()
44
    {
45
        $this->assertInstanceOf(HandlerInterface::class, $this->textBlock);
46
    }
47
48
    /**
49
     * @expectedException \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException
50
     * @expectedExceptionMessage Argument '$params[0]' is invalid: Field type handlers require at least a field identifier.
51
     */
52
    public function testGettingTagsWithoutFieldIdentifier()
53
    {
54
        $this->textBlock->getMetaTags('some_tag', array());
55
    }
56
57
    /**
58
     * @expectedException \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException
59
     * @expectedExceptionMessage Argument '$params[0]' is invalid: Field 'some_value' does not exist in content.
60
     */
61
    public function testGettingTagsWithNonExistentField()
62
    {
63
        $this->translationHelper->expects($this->once())
64
            ->method('getTranslatedField')
65
            ->willReturn(null);
66
67
        $this->textBlock->getMetaTags('some_tag', array('some_value'));
68
    }
69
70
    /**
71
     * @expectedException \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException
72
     * @expectedExceptionMessage Argument '$params[0]' is invalid: Netgen\Bundle\OpenGraphBundle\Handler\FieldType\TextBlock field type handler does not support field with identifier ''.
73
     */
74
    public function testGettingTagsWithUnsupportedField()
75
    {
76
        $this->translationHelper->expects($this->once())
77
            ->method('getTranslatedField')
78
            ->willReturn(new Field());
79
80
        $this->textBlock->getMetaTags('some_tag', array('some_value'));
81
    }
82
83
    public function testGettingTagsWithEmptyField()
84
    {
85
        $this->translationHelper->expects($this->once())
86
            ->method('getTranslatedField')
87
            ->willReturn($this->field);
88
89
        $this->fieldHelper->expects($this->once())
90
            ->method('isFieldEmpty')
91
            ->willReturn(true);
92
93
        $this->textBlock->getMetaTags('some_tag', array('some_value'));
94
    }
95
96
    public function testGettingTags()
97
    {
98
        $this->translationHelper->expects($this->once())
99
            ->method('getTranslatedField')
100
            ->willReturn($this->field);
101
102
        $this->textBlock->getMetaTags('some_tag', array('some_value'));
103
    }
104
105
    public function testGettingTagsWithMultipleArgumentsInArray()
106
    {
107
        $this->translationHelper->expects($this->once())
108
            ->method('getTranslatedField')
109
            ->willReturn($this->field);
110
111
        $this->textBlock->getMetaTags('some_tag', array('some_value', 'some_value_2'));
112
    }
113
}
114