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.
Passed
Pull Request — master (#37)
by Simone
09:09
created

OperatorTest::testIsEqualByDefault()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
use Mado\QueryBundle\Objects\Operator;
4
use Mado\QueryBundle\Vocabulary\Operators;
5
use PHPUnit\Framework\TestCase;
6
7
/**
8
 * @coversDefaultClass \Mado\QueryBundle\Objects\Operator
9
 */
10
class OperatorTest extends TestCase
11
{
12
    /**
13
     * @covers ::__construct
14
     * @covers ::getDefault
15
     * @covers ::getMeta
16
     */
17
    public function testIsEqualByDefault()
18
    {
19
        $op = Operator::getDefault();
20
        $this->assertEquals('=', $op->getMeta());
21
    }
22
23
    /**
24
     * @covers ::fromRawValue
25
     * @expectedException \RuntimeException
26
     * @expectedExceptionMessage Raw operator must contain `meta` parameter
27
     */
28
    public function testCreationIsInvalidWithoutMetaParameter()
29
    {
30
        Operator::fromRawValue([
31
            // invalid raw value
32
        ]);
33
    }
34
35
    /**
36
     * @covers ::__construct
37
     * @covers ::fromRawValue
38
     * @covers ::getMeta
39
     */
40
    public function testCreationIsValidWithMetaParameter()
41
    {
42
        $op = Operator::fromRawValue([
43
            'meta' => '=',
44
        ]);
45
46
        $this->assertEquals(
47
            '=',
48
            $op->getMeta()
49
        );
50
    }
51
52
    /**
53
     * @covers ::fromRawValue
54
     * @covers ::__construct
55
     * @covers ::getSubstitutionPattern
56
     * @covers ::haveSubstitutionPattern
57
     * @expectedException \RuntimeException
58
     * @expectedExceptionMessage Oops! Current operator have not substitution pattern.
59
     */
60
    public function testThrowExceptionIfSubstitutionPatternIsRequsted()
61
    {
62
        $op = Operator::fromRawValue([
63
            'meta' => '=',
64
        ]);
65
66
        $op->getSubstitutionPattern();
67
    }
68
69
    /**
70
     * @covers ::fromRawValue
71
     * @covers ::__construct
72
     * @covers ::getSubstitutionPattern
73
     * @covers ::haveSubstitutionPattern
74
     */
75
    public function testProvideSubstitutionPatternIfDefinedInConstructor()
76
    {
77
        $op = Operator::fromRawValue([
78
            'meta' => '=',
79
            'substitution_pattern' => 'foo',
80
        ]);
81
82
        $this->assertEquals(
83
            'foo',
84
            $op->getSubstitutionPattern()
85
        );
86
    }
87
88
    /**
89
     * @covers ::fromFilteringObject
90
     * @covers ::__construct
91
     * @covers ::getDefault
92
     */
93
    public function testReturnDefaultOperatorWheneverFilteringObjectHasNoOperator()
94
    {
95
        $this->filteringObject = $this
0 ignored issues
show
Bug Best Practice introduced by
The property filteringObject does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
96
            ->getMockBuilder('Mado\QueryBundle\Objects\FilteringObject')
97
            ->disableOriginalConstructor()
98
            ->getMock();
99
        $this->filteringObject->expects($this->once())
100
            ->method('hasOperator')
101
            ->will($this->returnValue(false));
102
103
        $op = Operator::fromFilteringObject($this->filteringObject);
104
105
        $this->assertEquals(
106
            $op,
107
            Operator::getDefault()
108
        );
109
    }
110
111
    /**
112
     * @covers ::fromFilteringObject
113
     * @covers ::__construct
114
     * @covers ::getDefault
115
     */
116
    public function testDontReturnDefaultOperatorWheneverFilteringObjectHasOperator()
117
    {
118
        $this->filteringObject = $this
0 ignored issues
show
Bug Best Practice introduced by
The property filteringObject does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
119
            ->getMockBuilder('Mado\QueryBundle\Objects\FilteringObject')
120
            ->disableOriginalConstructor()
121
            ->getMock();
122
        $this->filteringObject->expects($this->once())
123
            ->method('hasOperator')
124
            ->will($this->returnValue(true));
125
        $this->filteringObject->expects($this->once())
126
            ->method('getOperator')
127
            ->will($this->returnValue('list'));
128
129
        $op = Operator::fromFilteringObject($this->filteringObject);
130
131
        $this->assertNotEquals($op, Operator::getDefault());
132
    }
133
134
    /**
135
     * @covers ::fromFilteringObject
136
     * @covers ::__construct
137
     * @covers ::getDefault
138
     * @covers ::getRawValue
139
     */
140
    public function testProvideRawOperatorValue()
141
    {
142
        $this->filteringObject = $this
0 ignored issues
show
Bug Best Practice introduced by
The property filteringObject does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
143
            ->getMockBuilder('Mado\QueryBundle\Objects\FilteringObject')
144
            ->disableOriginalConstructor()
145
            ->getMock();
146
        $this->filteringObject->expects($this->once())
147
            ->method('hasOperator')
148
            ->will($this->returnValue(true));
149
        $this->filteringObject->expects($this->once())
150
            ->method('getOperator')
151
            ->will($this->returnValue('list'));
152
153
        $op = Operator::fromFilteringObject($this->filteringObject);
154
155
        $operator = [
0 ignored issues
show
Unused Code introduced by
The assignment to $operator is dead and can be removed.
Loading history...
156
            'meta' => 'IN',
157
            'substitution_pattern' => '({string})',
158
        ];
159
160
        $operator = Operators::get('list');
161
162
        $this->assertEquals(
163
            $operator,
164
            $op->getRawValue()
165
        );
166
    }
167
}
168