|
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\Spec; |
|
15
|
|
|
|
|
16
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
17
|
|
|
use Doctrine\ORM\QueryBuilder; |
|
18
|
|
|
use Happyr\DoctrineSpecification\Filter\Like; |
|
19
|
|
|
use Happyr\DoctrineSpecification\Specification\Specification; |
|
20
|
|
|
use PhpSpec\ObjectBehavior; |
|
21
|
|
|
|
|
22
|
|
|
class LikeSpec extends ObjectBehavior |
|
23
|
|
|
{ |
|
24
|
|
|
private $field = 'foo'; |
|
25
|
|
|
|
|
26
|
|
|
private $value = 'bar'; |
|
27
|
|
|
|
|
28
|
|
|
public function let() |
|
29
|
|
|
{ |
|
30
|
|
|
$this->beConstructedWith($this->field, $this->value, Like::CONTAINS, 'dqlAlias'); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function it_is_a_specification() |
|
34
|
|
|
{ |
|
35
|
|
|
$this->shouldHaveType(Specification::class); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function it_surrounds_with_wildcards_when_using_contains(QueryBuilder $qb, ArrayCollection $parameters) |
|
39
|
|
|
{ |
|
40
|
|
|
$this->beConstructedWith($this->field, $this->value, Like::CONTAINS, 'dqlAlias'); |
|
41
|
|
|
$qb->getParameters()->willReturn($parameters); |
|
42
|
|
|
$parameters->count()->willReturn(1); |
|
43
|
|
|
|
|
44
|
|
|
$qb->setParameter('comparison_1', '%bar%')->shouldBeCalled(); |
|
45
|
|
|
|
|
46
|
|
|
$this->match($qb, null); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function it_starts_with_wildcard_when_using_ends_with(QueryBuilder $qb, ArrayCollection $parameters) |
|
50
|
|
|
{ |
|
51
|
|
|
$this->beConstructedWith($this->field, $this->value, Like::ENDS_WITH, 'dqlAlias'); |
|
52
|
|
|
$qb->getParameters()->willReturn($parameters); |
|
53
|
|
|
$parameters->count()->willReturn(1); |
|
54
|
|
|
|
|
55
|
|
|
$qb->setParameter('comparison_1', '%bar')->shouldBeCalled(); |
|
56
|
|
|
|
|
57
|
|
|
$this->match($qb, null); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function it_ends_with_wildcard_when_using_starts_with(QueryBuilder $qb, ArrayCollection $parameters) |
|
61
|
|
|
{ |
|
62
|
|
|
$this->beConstructedWith($this->field, $this->value, Like::STARTS_WITH, 'dqlAlias'); |
|
63
|
|
|
$qb->getParameters()->willReturn($parameters); |
|
64
|
|
|
$parameters->count()->willReturn(1); |
|
65
|
|
|
|
|
66
|
|
|
$qb->setParameter('comparison_1', 'bar%')->shouldBeCalled(); |
|
67
|
|
|
|
|
68
|
|
|
$this->match($qb, null); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|