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\Filter; |
16
|
|
|
|
17
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
18
|
|
|
use Doctrine\ORM\QueryBuilder; |
19
|
|
|
use Happyr\DoctrineSpecification\Filter\Filter; |
20
|
|
|
use Happyr\DoctrineSpecification\Filter\GreaterThan; |
21
|
|
|
use PhpSpec\ObjectBehavior; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @mixin GreaterThan |
25
|
|
|
*/ |
26
|
|
View Code Duplication |
class GreaterThanSpec extends ObjectBehavior |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
public function let() |
29
|
|
|
{ |
30
|
|
|
$this->beConstructedWith('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('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
|
|
|
|
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.