1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace tests\Happyr\DoctrineSpecification\Spec; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
6
|
|
|
use Doctrine\ORM\QueryBuilder; |
7
|
|
|
use Happyr\DoctrineSpecification\Filter\Like; |
8
|
|
|
use PhpSpec\ObjectBehavior; |
9
|
|
|
|
10
|
|
|
class LikeSpec extends ObjectBehavior |
11
|
|
|
{ |
12
|
|
|
private $field = 'foo'; |
13
|
|
|
|
14
|
|
|
private $value = 'bar'; |
15
|
|
|
|
16
|
|
|
public function let() |
17
|
|
|
{ |
18
|
|
|
$this->beConstructedWith($this->field, $this->value, Like::CONTAINS, 'dqlAlias'); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function it_is_a_specification() |
22
|
|
|
{ |
23
|
|
|
$this->shouldHaveType('Happyr\DoctrineSpecification\Specification\Specification'); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
View Code Duplication |
public function it_surrounds_with_wildcards_when_using_contains(QueryBuilder $qb, ArrayCollection $parameters) |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
$this->beConstructedWith($this->field, $this->value, Like::CONTAINS, 'dqlAlias'); |
29
|
|
|
$qb->getParameters()->willReturn($parameters); |
30
|
|
|
$parameters->count()->willReturn(1); |
31
|
|
|
|
32
|
|
|
$qb->setParameter('comparison_1', '%bar%')->shouldBeCalled(); |
33
|
|
|
|
34
|
|
|
$this->match($qb, null); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
View Code Duplication |
public function it_starts_with_wildcard_when_using_ends_with(QueryBuilder $qb, ArrayCollection $parameters) |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
$this->beConstructedWith($this->field, $this->value, Like::ENDS_WITH, 'dqlAlias'); |
40
|
|
|
$qb->getParameters()->willReturn($parameters); |
41
|
|
|
$parameters->count()->willReturn(1); |
42
|
|
|
|
43
|
|
|
$qb->setParameter('comparison_1', '%bar')->shouldBeCalled(); |
44
|
|
|
|
45
|
|
|
$this->match($qb, null); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
View Code Duplication |
public function it_ends_with_wildcard_when_using_starts_with(QueryBuilder $qb, ArrayCollection $parameters) |
|
|
|
|
49
|
|
|
{ |
50
|
|
|
$this->beConstructedWith($this->field, $this->value, Like::STARTS_WITH, 'dqlAlias'); |
51
|
|
|
$qb->getParameters()->willReturn($parameters); |
52
|
|
|
$parameters->count()->willReturn(1); |
53
|
|
|
|
54
|
|
|
$qb->setParameter('comparison_1', 'bar%')->shouldBeCalled(); |
55
|
|
|
|
56
|
|
|
$this->match($qb, null); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
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.