1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace tests\Happyr\DoctrineSpecification\Filter; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
6
|
|
|
use Doctrine\ORM\QueryBuilder; |
7
|
|
|
use Happyr\DoctrineSpecification\Filter\Comparison; |
8
|
|
|
use PhpSpec\ObjectBehavior; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @mixin Comparison |
12
|
|
|
*/ |
13
|
|
|
class ComparisonSpec extends ObjectBehavior |
14
|
|
|
{ |
15
|
|
|
public function let() |
16
|
|
|
{ |
17
|
|
|
$this->beConstructedWith(Comparison::GT, 'age', 18, 'a'); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function it_is_an_expression() |
21
|
|
|
{ |
22
|
|
|
$this->shouldBeAnInstanceOf('Happyr\DoctrineSpecification\Filter\Filter'); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function it_returns_comparison_object(QueryBuilder $qb, ArrayCollection $parameters) |
26
|
|
|
{ |
27
|
|
|
$qb->getParameters()->willReturn($parameters); |
28
|
|
|
$parameters->count()->willReturn(10); |
29
|
|
|
|
30
|
|
|
$qb->setParameter('comparison_10', 18)->shouldBeCalled(); |
31
|
|
|
|
32
|
|
|
$comparison = $this->getFilter($qb, null); |
33
|
|
|
|
34
|
|
|
$comparison->shouldReturn('a.age > :comparison_10'); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function it_uses_comparison_specific_dql_alias_if_passed(QueryBuilder $qb, ArrayCollection $parameters) |
38
|
|
|
{ |
39
|
|
|
$this->beConstructedWith(Comparison::GT, 'age', 18, null); |
40
|
|
|
|
41
|
|
|
$qb->getParameters()->willReturn($parameters); |
42
|
|
|
$parameters->count()->willReturn(10); |
43
|
|
|
|
44
|
|
|
$qb->setParameter('comparison_10', 18)->shouldBeCalled(); |
45
|
|
|
|
46
|
|
|
$this->getFilter($qb, 'x')->shouldReturn('x.age > :comparison_10'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function it_validates_operator() |
50
|
|
|
{ |
51
|
|
|
$this->shouldThrow('Happyr\DoctrineSpecification\Exception\InvalidArgumentException')->during('__construct', array('==', 'age', 18, null)); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|