Completed
Push — theme-collector ( e0987d )
by Kamil
23:25
created

ExpressionBuilderSpec::it_is_initializable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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
declare(strict_types=1);
13
14
namespace spec\Sylius\Bundle\GridBundle\Doctrine\PHPCRODM;
15
16
use Doctrine\Common\Collections\Expr\Comparison;
17
use Doctrine\Common\Collections\ExpressionBuilder as CollectionsExpressionBuilder;
18
use PhpSpec\ObjectBehavior;
19
use Sylius\Bundle\GridBundle\Doctrine\PHPCRODM\ExtraComparison;
20
21
/**
22
 * @require Doctrine\ODM\PHPCR\DocumentManagerInterface
23
 */
24
final class ExpressionBuilderSpec extends ObjectBehavior
25
{
26
    function let(CollectionsExpressionBuilder $expressionBuilder): void
27
    {
28
        $this->beConstructedWith($expressionBuilder);
29
    }
30
31
    function it_builds_andx(
32
        Comparison $comparison,
33
        CollectionsExpressionBuilder $expressionBuilder
34
    ): void {
35
        $this->andX([$comparison]);
36
        $expressionBuilder->andX([$comparison])->shouldHaveBeenCalled();
37
    }
38
39
    function it_builds_orx(
40
        Comparison $comparison,
41
        CollectionsExpressionBuilder $expressionBuilder
42
    ): void {
43
        $this->orX([$comparison]);
44
        $expressionBuilder->orX([$comparison])->shouldHaveBeenCalled();
45
    }
46
47
    function it_builds_equals(
48
        CollectionsExpressionBuilder $expressionBuilder
49
    ): void {
50
        $this->equals('o.foo', 'value');
51
        $expressionBuilder->eq('o.foo', 'value')->shouldHaveBeenCalled();
52
    }
53
54
    function it_builds_not_equals(
55
        CollectionsExpressionBuilder $expressionBuilder
56
    ): void {
57
        $this->notEquals('o.foo', 'value');
58
        $expressionBuilder->neq('o.foo', 'value')->shouldHaveBeenCalled();
59
    }
60
61
    function it_builds_less_than_or_equal(
62
        CollectionsExpressionBuilder $expressionBuilder
63
    ): void {
64
        $this->lessThanOrEqual('o.foo', 'value');
65
        $expressionBuilder->lte('o.foo', 'value')->shouldHaveBeenCalled();
66
    }
67
68
    function it_builds_greater_than(
69
        CollectionsExpressionBuilder $expressionBuilder
70
    ): void {
71
        $this->greaterThan('o.foo', 'value');
72
        $expressionBuilder->gt('o.foo', 'value')->shouldHaveBeenCalled();
73
    }
74
75
    function it_builds_greater_than_or_equal(
76
        CollectionsExpressionBuilder $expressionBuilder
77
    ): void {
78
        $this->greaterThanOrequal('o.foo', 'value');
79
        $expressionBuilder->gte('o.foo', 'value')->shouldHaveBeenCalled();
80
    }
81
82
    function it_builds_in(
83
        CollectionsExpressionBuilder $expressionBuilder
84
    ): void {
85
        $this->in('o.foo', ['value']);
86
        $expressionBuilder->in('o.foo', ['value'])->shouldHaveBeenCalled();
87
    }
88
89
    function it_builds_not_in(
90
        CollectionsExpressionBuilder $expressionBuilder
91
    ): void {
92
        $this->notIn('o.foo', ['value']);
93
        $expressionBuilder->notIn('o.foo', ['value'])->shouldHaveBeenCalled();
94
    }
95
96
    function it_builds_is_null(): void
97
    {
98
        $expr = $this->isNull('o.foo');
99
        $expr->getOperator()->shouldReturn(ExtraComparison::IS_NULL);
100
        $expr->getField()->shouldReturn('o.foo');
101
    }
102
103
    function it_builds_is_not_null(): void
104
    {
105
        $expr = $this->isNotNull('o.foo');
106
        $expr->getOperator()->shouldReturn(ExtraComparison::IS_NOT_NULL);
107
        $expr->getField()->shouldReturn('o.foo');
108
    }
109
110
    function it_builds_like(
111
        CollectionsExpressionBuilder $expressionBuilder
112
    ): void {
113
        $this->like('o.foo', 'value');
114
        $expressionBuilder->contains('o.foo', 'value')->shouldHaveBeenCalled();
115
    }
116
117
    function it_builds_not_like(): void
118
    {
119
        $expr = $this->notLike('o.foo', 'value');
120
        $expr->getOperator()->shouldReturn(ExtraComparison::NOT_CONTAINS);
121
        $expr->getField()->shouldReturn('o.foo');
122
    }
123
124
    function it_orders_by(): void
125
    {
126
        $this->orderBy('o.foo', 'asc');
127
        $this->getOrderBys()->shouldReturn([
128
            'o.foo' => 'asc',
129
        ]);
130
    }
131
132
    function it_adds_order_by(): void
133
    {
134
        $this->orderBy('o.foo', 'asc');
135
        $this->addOrderBy('o.bar', 'desc');
136
        $this->getOrderBys()->shouldReturn([
137
            'o.foo' => 'asc',
138
            'o.bar' => 'desc',
139
        ]);
140
    }
141
}
142