|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace tests\Happyr\DoctrineSpecification\Logic; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\ORM\Query\Expr; |
|
6
|
|
|
use Doctrine\ORM\QueryBuilder; |
|
7
|
|
|
use Happyr\DoctrineSpecification\Filter\Filter; |
|
8
|
|
|
use Happyr\DoctrineSpecification\Logic\LogicX; |
|
9
|
|
|
use Happyr\DoctrineSpecification\Specification\Specification; |
|
10
|
|
|
use PhpSpec\ObjectBehavior; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @mixin LogicX |
|
14
|
|
|
*/ |
|
15
|
|
|
class LogicXSpec extends ObjectBehavior |
|
16
|
|
|
{ |
|
17
|
|
|
const EXPRESSION = 'andX'; |
|
18
|
|
|
|
|
19
|
|
|
public function let(Specification $specificationA, Specification $specificationB) |
|
20
|
|
|
{ |
|
21
|
|
|
$this->beConstructedWith(self::EXPRESSION, array($specificationA, $specificationB)); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function it_is_a_specification() |
|
25
|
|
|
{ |
|
26
|
|
|
$this->shouldHaveType('Happyr\DoctrineSpecification\Specification\Specification'); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function it_modifies_all_child_queries(QueryBuilder $queryBuilder, Specification $specificationA, Specification $specificationB) |
|
30
|
|
|
{ |
|
31
|
|
|
$dqlAlias = 'a'; |
|
32
|
|
|
|
|
33
|
|
|
$specificationA->modify($queryBuilder, $dqlAlias)->shouldBeCalled(); |
|
34
|
|
|
$specificationB->modify($queryBuilder, $dqlAlias)->shouldBeCalled(); |
|
35
|
|
|
|
|
36
|
|
|
$this->modify($queryBuilder, $dqlAlias); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function it_composes_and_child_with_expression(QueryBuilder $qb, Expr $expression, Specification $specificationA, Specification $specificationB, $x, $y) |
|
40
|
|
|
{ |
|
41
|
|
|
$dqlAlias = 'a'; |
|
42
|
|
|
|
|
43
|
|
|
$specificationA->getFilter($qb, $dqlAlias)->willReturn($x); |
|
44
|
|
|
$specificationB->getFilter($qb, $dqlAlias)->willReturn($y); |
|
45
|
|
|
$qb->expr()->willReturn($expression); |
|
46
|
|
|
|
|
47
|
|
|
$expression->{self::EXPRESSION}($x, $y)->shouldBeCalled(); |
|
48
|
|
|
|
|
49
|
|
|
$this->getFilter($qb, $dqlAlias); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function it_supports_expressions(QueryBuilder $qb, Expr $expression, Filter $exprA, Filter $exprB, $x, $y) |
|
53
|
|
|
{ |
|
54
|
|
|
$this->beConstructedWith(self::EXPRESSION, array($exprA, $exprB)); |
|
55
|
|
|
|
|
56
|
|
|
$dqlAlias = 'a'; |
|
57
|
|
|
|
|
58
|
|
|
$exprA->getFilter($qb, $dqlAlias)->willReturn($x); |
|
59
|
|
|
$exprB->getFilter($qb, $dqlAlias)->willReturn($y); |
|
60
|
|
|
$qb->expr()->willReturn($expression); |
|
61
|
|
|
|
|
62
|
|
|
$expression->{self::EXPRESSION}($x, $y)->shouldBeCalled(); |
|
63
|
|
|
|
|
64
|
|
|
$this->getFilter($qb, $dqlAlias); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|