1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* This file is part of the Happyr Doctrine Specification package. |
6
|
|
|
* |
7
|
|
|
* (c) Tobias Nyholm <[email protected]> |
8
|
|
|
* Kacper Gunia <[email protected]> |
9
|
|
|
* Peter Gribanov <[email protected]> |
10
|
|
|
* |
11
|
|
|
* For the full copyright and license information, please view the LICENSE |
12
|
|
|
* file that was distributed with this source code. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace tests\Happyr\DoctrineSpecification\Logic; |
16
|
|
|
|
17
|
|
|
use Doctrine\ORM\Query\Expr; |
18
|
|
|
use Doctrine\ORM\QueryBuilder; |
19
|
|
|
use Happyr\DoctrineSpecification\Filter\Filter; |
20
|
|
|
use Happyr\DoctrineSpecification\Logic\OrX; |
21
|
|
|
use Happyr\DoctrineSpecification\Specification\Specification; |
22
|
|
|
use PhpSpec\ObjectBehavior; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @mixin OrX |
26
|
|
|
*/ |
27
|
|
View Code Duplication |
class OrXSpec extends ObjectBehavior |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
public function let(Specification $specificationA, Specification $specificationB) |
30
|
|
|
{ |
31
|
|
|
$this->beConstructedWith($specificationA, $specificationB); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function it_is_a_specification() |
35
|
|
|
{ |
36
|
|
|
$this->shouldHaveType(Specification::class); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function it_modifies_all_child_queries(QueryBuilder $queryBuilder, Specification $specificationA, Specification $specificationB) |
40
|
|
|
{ |
41
|
|
|
$dqlAlias = 'a'; |
42
|
|
|
|
43
|
|
|
$specificationA->modify($queryBuilder, $dqlAlias)->shouldBeCalled(); |
44
|
|
|
$specificationB->modify($queryBuilder, $dqlAlias)->shouldBeCalled(); |
45
|
|
|
|
46
|
|
|
$this->modify($queryBuilder, $dqlAlias); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function it_composes_and_child_with_expression(QueryBuilder $qb, Expr $expression, Specification $specificationA, Specification $specificationB, $x, $y) |
50
|
|
|
{ |
51
|
|
|
$dqlAlias = 'a'; |
52
|
|
|
|
53
|
|
|
$specificationA->getFilter($qb, $dqlAlias)->willReturn($x); |
54
|
|
|
$specificationB->getFilter($qb, $dqlAlias)->willReturn($y); |
55
|
|
|
$qb->expr()->willReturn($expression); |
56
|
|
|
|
57
|
|
|
$expression->orX($x, $y)->shouldBeCalled(); |
58
|
|
|
|
59
|
|
|
$this->getFilter($qb, $dqlAlias); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function it_supports_expressions(QueryBuilder $qb, Expr $expression, Filter $exprA, Filter $exprB, $x, $y) |
63
|
|
|
{ |
64
|
|
|
$this->beConstructedWith($exprA, $exprB); |
65
|
|
|
|
66
|
|
|
$dqlAlias = 'a'; |
67
|
|
|
|
68
|
|
|
$exprA->getFilter($qb, $dqlAlias)->willReturn($x); |
69
|
|
|
$exprB->getFilter($qb, $dqlAlias)->willReturn($y); |
70
|
|
|
$qb->expr()->willReturn($expression); |
71
|
|
|
|
72
|
|
|
$expression->orX($x, $y)->shouldBeCalled(); |
73
|
|
|
|
74
|
|
|
$this->getFilter($qb, $dqlAlias); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.