|
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\Logic; |
|
15
|
|
|
|
|
16
|
|
|
use Doctrine\ORM\Query\Expr; |
|
17
|
|
|
use Doctrine\ORM\QueryBuilder; |
|
18
|
|
|
use Happyr\DoctrineSpecification\Filter\Filter; |
|
19
|
|
|
use Happyr\DoctrineSpecification\Logic\LogicX; |
|
20
|
|
|
use Happyr\DoctrineSpecification\Specification\Specification; |
|
21
|
|
|
use PhpSpec\ObjectBehavior; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @mixin LogicX |
|
25
|
|
|
*/ |
|
26
|
|
|
class LogicXSpec extends ObjectBehavior |
|
27
|
|
|
{ |
|
28
|
|
|
const EXPRESSION = 'andX'; |
|
29
|
|
|
|
|
30
|
|
|
public function let(Specification $specificationA, Specification $specificationB) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->beConstructedWith(self::EXPRESSION, [$specificationA, $specificationB]); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function it_is_a_specification() |
|
36
|
|
|
{ |
|
37
|
|
|
$this->shouldHaveType(Specification::class); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function it_modifies_all_child_queries(QueryBuilder $queryBuilder, Specification $specificationA, Specification $specificationB) |
|
41
|
|
|
{ |
|
42
|
|
|
$dqlAlias = 'a'; |
|
43
|
|
|
|
|
44
|
|
|
$specificationA->modify($queryBuilder, $dqlAlias)->shouldBeCalled(); |
|
45
|
|
|
$specificationB->modify($queryBuilder, $dqlAlias)->shouldBeCalled(); |
|
46
|
|
|
|
|
47
|
|
|
$this->modify($queryBuilder, $dqlAlias); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function it_composes_and_child_with_expression(QueryBuilder $qb, Expr $expression, Specification $specificationA, Specification $specificationB, $x, $y) |
|
51
|
|
|
{ |
|
52
|
|
|
$dqlAlias = 'a'; |
|
53
|
|
|
|
|
54
|
|
|
$specificationA->getFilter($qb, $dqlAlias)->willReturn($x); |
|
55
|
|
|
$specificationB->getFilter($qb, $dqlAlias)->willReturn($y); |
|
56
|
|
|
$qb->expr()->willReturn($expression); |
|
57
|
|
|
|
|
58
|
|
|
$expression->{self::EXPRESSION}($x, $y)->shouldBeCalled(); |
|
59
|
|
|
|
|
60
|
|
|
$this->getFilter($qb, $dqlAlias); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function it_supports_expressions(QueryBuilder $qb, Expr $expression, Filter $exprA, Filter $exprB, $x, $y) |
|
64
|
|
|
{ |
|
65
|
|
|
$this->beConstructedWith(self::EXPRESSION, [$exprA, $exprB]); |
|
66
|
|
|
|
|
67
|
|
|
$dqlAlias = 'a'; |
|
68
|
|
|
|
|
69
|
|
|
$exprA->getFilter($qb, $dqlAlias)->willReturn($x); |
|
70
|
|
|
$exprB->getFilter($qb, $dqlAlias)->willReturn($y); |
|
71
|
|
|
$qb->expr()->willReturn($expression); |
|
72
|
|
|
|
|
73
|
|
|
$expression->{self::EXPRESSION}($x, $y)->shouldBeCalled(); |
|
74
|
|
|
|
|
75
|
|
|
$this->getFilter($qb, $dqlAlias); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|