|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Mado\QueryBundle\Objects\Operator; |
|
4
|
|
|
use PHPUnit\Framework\TestCase; |
|
5
|
|
|
|
|
6
|
|
|
class OperatorTest extends TestCase |
|
7
|
|
|
{ |
|
8
|
|
|
public function testIsEqualByDefault() |
|
9
|
|
|
{ |
|
10
|
|
|
$op = Operator::getDefault(); |
|
11
|
|
|
$this->assertEquals('=', $op->getMeta()); |
|
12
|
|
|
} |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @expectedException \RuntimeException |
|
16
|
|
|
* @expectedExceptionMessage Raw operator must contain `meta` parameter |
|
17
|
|
|
*/ |
|
18
|
|
|
public function testCreationIsInvalidWithoutMetaParameter() |
|
19
|
|
|
{ |
|
20
|
|
|
Operator::fromRawValue([ |
|
21
|
|
|
// invalid raw value |
|
22
|
|
|
]); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function testCreationIsValidWithMetaParameter() |
|
26
|
|
|
{ |
|
27
|
|
|
$op = Operator::fromRawValue([ |
|
28
|
|
|
'meta' => '=', |
|
29
|
|
|
]); |
|
30
|
|
|
|
|
31
|
|
|
$this->assertEquals( |
|
32
|
|
|
'=', |
|
33
|
|
|
$op->getMeta() |
|
34
|
|
|
); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @expectedException \RuntimeException |
|
39
|
|
|
* @expectedExceptionMessage Oops! Current operator have not substitution pattern. |
|
40
|
|
|
*/ |
|
41
|
|
|
public function testThrowExceptionIfSubstitutionPatternIsRequsted() |
|
42
|
|
|
{ |
|
43
|
|
|
$op = Operator::fromRawValue([ |
|
44
|
|
|
'meta' => '=', |
|
45
|
|
|
]); |
|
46
|
|
|
|
|
47
|
|
|
$op->getSubstitutionPattern(); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testProvideSubstitutionPatternIfDefinedInConstructor() |
|
51
|
|
|
{ |
|
52
|
|
|
$op = Operator::fromRawValue([ |
|
53
|
|
|
'meta' => '=', |
|
54
|
|
|
'substitution_pattern' => 'foo', |
|
55
|
|
|
]); |
|
56
|
|
|
|
|
57
|
|
|
$this->assertEquals( |
|
58
|
|
|
'foo', |
|
59
|
|
|
$op->getSubstitutionPattern() |
|
60
|
|
|
); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function testReturnDefaultOperatorWheneverFilteringObjectHasNoOperator() |
|
64
|
|
|
{ |
|
65
|
|
|
$this->filteringObject = $this |
|
|
|
|
|
|
66
|
|
|
->getMockBuilder('Mado\QueryBundle\Objects\FilteringObject') |
|
67
|
|
|
->disableOriginalConstructor() |
|
68
|
|
|
->getMock(); |
|
69
|
|
|
$this->filteringObject->expects($this->once()) |
|
70
|
|
|
->method('hasOperator') |
|
71
|
|
|
->will($this->returnValue(false)); |
|
72
|
|
|
|
|
73
|
|
|
$op = Operator::fromFilteringObject($this->filteringObject); |
|
74
|
|
|
|
|
75
|
|
|
$this->assertEquals( |
|
76
|
|
|
$op, |
|
77
|
|
|
Operator::getDefault() |
|
78
|
|
|
); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function testDontReturnDefaultOperatorWheneverFilteringObjectHasOperator() |
|
82
|
|
|
{ |
|
83
|
|
|
$this->filteringObject = $this |
|
|
|
|
|
|
84
|
|
|
->getMockBuilder('Mado\QueryBundle\Objects\FilteringObject') |
|
85
|
|
|
->disableOriginalConstructor() |
|
86
|
|
|
->getMock(); |
|
87
|
|
|
$this->filteringObject->expects($this->once()) |
|
88
|
|
|
->method('hasOperator') |
|
89
|
|
|
->will($this->returnValue(true)); |
|
90
|
|
|
$this->filteringObject->expects($this->once()) |
|
91
|
|
|
->method('getOperator') |
|
92
|
|
|
->will($this->returnValue('list')); |
|
93
|
|
|
|
|
94
|
|
|
$op = Operator::fromFilteringObject($this->filteringObject); |
|
95
|
|
|
|
|
96
|
|
|
$this->assertNotEquals($op, Operator::getDefault()); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|