ComparisonSpec   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 4
dl 0
loc 46
c 0
b 0
f 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_an_expression() 0 4 1
A it_returns_comparison_object() 0 11 1
A it_uses_comparison_specific_dql_alias_if_passed() 0 11 1
A it_validates_operator() 0 4 1
A it_not_support_like_operator() 0 4 1
1
<?php
2
3
/**
4
 * This file is part of the Happyr Doctrine Specification package.
5
 *
6
 * (c) Tobias Nyholm <[email protected]>
7
 *     Kacper Gunia <[email protected]>
8
 *     Peter Gribanov <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace tests\Happyr\DoctrineSpecification\Filter;
15
16
use Doctrine\Common\Collections\ArrayCollection;
17
use Doctrine\ORM\QueryBuilder;
18
use Happyr\DoctrineSpecification\Exception\InvalidArgumentException;
19
use Happyr\DoctrineSpecification\Filter\Comparison;
20
use Happyr\DoctrineSpecification\Filter\Filter;
21
use PhpSpec\ObjectBehavior;
22
23
/**
24
 * @mixin Comparison
25
 */
26
class ComparisonSpec extends ObjectBehavior
27
{
28
    public function let()
29
    {
30
        $this->beConstructedWith(Comparison::GT, 'age', 18, 'a');
31
    }
32
33
    public function it_is_an_expression()
34
    {
35
        $this->shouldBeAnInstanceOf(Filter::class);
36
    }
37
38
    public function it_returns_comparison_object(QueryBuilder $qb, ArrayCollection $parameters)
39
    {
40
        $qb->getParameters()->willReturn($parameters);
41
        $parameters->count()->willReturn(10);
42
43
        $qb->setParameter('comparison_10', 18, null)->shouldBeCalled();
44
45
        $comparison = $this->getFilter($qb, null);
46
47
        $comparison->shouldReturn('a.age > :comparison_10');
48
    }
49
50
    public function it_uses_comparison_specific_dql_alias_if_passed(QueryBuilder $qb, ArrayCollection $parameters)
51
    {
52
        $this->beConstructedWith(Comparison::GT, 'age', 18, null);
53
54
        $qb->getParameters()->willReturn($parameters);
55
        $parameters->count()->willReturn(10);
56
57
        $qb->setParameter('comparison_10', 18, null)->shouldBeCalled();
58
59
        $this->getFilter($qb, 'x')->shouldReturn('x.age > :comparison_10');
60
    }
61
62
    public function it_validates_operator()
63
    {
64
        $this->shouldThrow(InvalidArgumentException::class)->during('__construct', ['==', 'age', 18, null]);
65
    }
66
67
    public function it_not_support_like_operator()
68
    {
69
        $this->shouldThrow(InvalidArgumentException::class)->during('__construct', ['like', 'name', 'Tobias%', null]);
70
    }
71
}
72