1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace spec\Sylius\Bundle\GridBundle\Doctrine\PHPCRODM; |
13
|
|
|
|
14
|
|
|
use PhpSpec\ObjectBehavior; |
15
|
|
|
use Prophecy\Argument; |
16
|
|
|
use Doctrine\Common\Collections\ExpressionBuilder as CollectionsExpressionBuilder; |
17
|
|
|
use Sylius\Bundle\GridBundle\Doctrine\PHPCRODM\ExpressionBuilder; |
18
|
|
|
use Doctrine\Common\Collections\Expr\Comparison; |
19
|
|
|
use Sylius\Bundle\GridBundle\Doctrine\PHPCRODM\ExtraComparison; |
20
|
|
|
|
21
|
|
|
class ExpressionBuilderSpec extends ObjectBehavior |
22
|
|
|
{ |
23
|
|
|
function let(CollectionsExpressionBuilder $expressionBuilder) |
24
|
|
|
{ |
25
|
|
|
$this->beConstructedWith($expressionBuilder); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
function it_is_initializable() |
29
|
|
|
{ |
30
|
|
|
$this->shouldHaveType(ExpressionBuilder::class); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
function it_builds_andx( |
34
|
|
|
Comparison $comparison, |
35
|
|
|
CollectionsExpressionBuilder $expressionBuilder |
36
|
|
|
) |
37
|
|
|
{ |
38
|
|
|
$this->andX([$comparison]); |
39
|
|
|
$expressionBuilder->andX([$comparison])->shouldHaveBeenCalled(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
function it_builds_orx( |
43
|
|
|
Comparison $comparison, |
44
|
|
|
CollectionsExpressionBuilder $expressionBuilder |
45
|
|
|
) |
46
|
|
|
{ |
47
|
|
|
$this->orX([$comparison]); |
48
|
|
|
$expressionBuilder->orX([$comparison])->shouldHaveBeenCalled(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
function it_builds_equals( |
52
|
|
|
CollectionsExpressionBuilder $expressionBuilder |
53
|
|
|
) |
54
|
|
|
{ |
55
|
|
|
$this->equals('o.foo', 'value'); |
56
|
|
|
$expressionBuilder->eq('o.foo', 'value')->shouldHaveBeenCalled(); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
function it_builds_not_equals( |
60
|
|
|
CollectionsExpressionBuilder $expressionBuilder |
61
|
|
|
) |
62
|
|
|
{ |
63
|
|
|
$this->notEquals('o.foo', 'value'); |
64
|
|
|
$expressionBuilder->neq('o.foo', 'value')->shouldHaveBeenCalled(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
function it_builds_less_than_or_equal( |
68
|
|
|
CollectionsExpressionBuilder $expressionBuilder |
69
|
|
|
) |
70
|
|
|
{ |
71
|
|
|
$this->lessThanOrEqual('o.foo', 'value'); |
72
|
|
|
$expressionBuilder->lte('o.foo', 'value')->shouldHaveBeenCalled(); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
function it_builds_greater_than( |
76
|
|
|
CollectionsExpressionBuilder $expressionBuilder |
77
|
|
|
) |
78
|
|
|
{ |
79
|
|
|
$this->greaterThan('o.foo', 'value'); |
80
|
|
|
$expressionBuilder->gt('o.foo', 'value')->shouldHaveBeenCalled(); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
function it_builds_greater_than_or_equal( |
84
|
|
|
CollectionsExpressionBuilder $expressionBuilder |
85
|
|
|
) |
86
|
|
|
{ |
87
|
|
|
$this->greaterThanOrequal('o.foo', 'value'); |
88
|
|
|
$expressionBuilder->gte('o.foo', 'value')->shouldHaveBeenCalled(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
function it_builds_in( |
92
|
|
|
CollectionsExpressionBuilder $expressionBuilder |
93
|
|
|
) |
94
|
|
|
{ |
95
|
|
|
$this->in('o.foo', ['value']); |
96
|
|
|
$expressionBuilder->in('o.foo', ['value'])->shouldHaveBeenCalled(); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
function it_builds_not_in( |
100
|
|
|
CollectionsExpressionBuilder $expressionBuilder |
101
|
|
|
) |
102
|
|
|
{ |
103
|
|
|
$this->notIn('o.foo', ['value']); |
104
|
|
|
$expressionBuilder->notIn('o.foo', ['value'])->shouldHaveBeenCalled(); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
function it_builds_is_null() |
108
|
|
|
{ |
109
|
|
|
$expr = $this->isNull('o.foo'); |
110
|
|
|
$expr->getOperator()->shouldReturn(ExtraComparison::IS_NULL); |
111
|
|
|
$expr->getField()->shouldReturn('o.foo'); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
function it_builds_is_not_null() |
115
|
|
|
{ |
116
|
|
|
$expr = $this->isNotNull('o.foo'); |
117
|
|
|
$expr->getOperator()->shouldReturn(ExtraComparison::IS_NOT_NULL); |
118
|
|
|
$expr->getField()->shouldReturn('o.foo'); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
function it_builds_like( |
122
|
|
|
CollectionsExpressionBuilder $expressionBuilder |
123
|
|
|
) |
124
|
|
|
{ |
125
|
|
|
$this->like('o.foo', 'value'); |
126
|
|
|
$expressionBuilder->contains('o.foo', 'value')->shouldHaveBeenCalled(); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
function it_builds_not_like() |
130
|
|
|
{ |
131
|
|
|
$expr = $this->notLike('o.foo', 'value'); |
132
|
|
|
$expr->getOperator()->shouldReturn(ExtraComparison::NOT_CONTAINS); |
133
|
|
|
$expr->getField()->shouldReturn('o.foo'); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
function it_orders_by() |
137
|
|
|
{ |
138
|
|
|
$this->orderBy('o.foo', 'asc'); |
139
|
|
|
$this->getOrderBys()->shouldReturn([ |
140
|
|
|
'o.foo' => 'asc', |
141
|
|
|
]); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
function it_adds_order_by() |
145
|
|
|
{ |
146
|
|
|
$this->orderBy('o.foo', 'asc'); |
147
|
|
|
$this->addOrderBy('o.bar', 'desc'); |
148
|
|
|
$this->getOrderBys()->shouldReturn([ |
149
|
|
|
'o.foo' => 'asc', |
150
|
|
|
'o.bar' => 'desc', |
151
|
|
|
]); |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|