Completed
Push — master ( f9a038...cc9983 )
by Kamil
22:34
created

ExpressionBuilderSpec   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 133
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 17
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 133
rs 10

17 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_initializable() 0 4 1
A it_builds_andx() 0 8 1
A it_builds_orx() 0 8 1
A it_builds_equals() 0 7 1
A it_builds_not_equals() 0 7 1
A it_builds_less_than_or_equal() 0 7 1
A it_builds_greater_than() 0 7 1
A it_builds_greater_than_or_equal() 0 7 1
A it_builds_in() 0 7 1
A it_builds_not_in() 0 7 1
A it_builds_is_null() 0 6 1
A it_builds_is_not_null() 0 6 1
A it_builds_like() 0 7 1
A it_builds_not_like() 0 6 1
A it_orders_by() 0 7 1
A it_adds_order_by() 0 9 1
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