1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace tests\Happyr\DoctrineSpecification\Operand; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
6
|
|
|
use Doctrine\DBAL\Types\Type; |
7
|
|
|
use Doctrine\ORM\QueryBuilder; |
8
|
|
|
use Happyr\DoctrineSpecification\Operand\Values; |
9
|
|
|
use PhpSpec\ObjectBehavior; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @mixin Values |
13
|
|
|
*/ |
14
|
|
View Code Duplication |
class ValuesSpec extends ObjectBehavior |
|
|
|
|
15
|
|
|
{ |
16
|
|
|
private $values = ['foo', 'bar']; |
17
|
|
|
|
18
|
|
|
private $valueType = null; |
19
|
|
|
|
20
|
|
|
public function let() |
21
|
|
|
{ |
22
|
|
|
$this->beConstructedWith($this->values, $this->valueType); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function it_is_a_values() |
26
|
|
|
{ |
27
|
|
|
$this->shouldBeAnInstanceOf('Happyr\DoctrineSpecification\Operand\Values'); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function it_is_a_operand() |
31
|
|
|
{ |
32
|
|
|
$this->shouldBeAnInstanceOf('Happyr\DoctrineSpecification\Operand\Operand'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function it_is_transformable(QueryBuilder $qb, ArrayCollection $parameters) |
36
|
|
|
{ |
37
|
|
|
$dqlAlias = 'a'; |
38
|
|
|
|
39
|
|
|
$qb->getParameters()->willReturn($parameters); |
40
|
|
|
$parameters->count()->willReturn(10); |
41
|
|
|
|
42
|
|
|
$qb->setParameter('comparison_10', $this->values, $this->valueType)->shouldBeCalled(); |
43
|
|
|
|
44
|
|
|
$this->transform($qb, $dqlAlias)->shouldReturn(':comparison_10'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function it_is_transformable_dbal_type(QueryBuilder $qb, ArrayCollection $parameters) |
48
|
|
|
{ |
49
|
|
|
$valueType = Type::DATE; |
50
|
|
|
$this->beConstructedWith($this->values, $valueType); |
51
|
|
|
|
52
|
|
|
$qb->getParameters()->willReturn($parameters); |
53
|
|
|
$parameters->count()->willReturn(10); |
54
|
|
|
|
55
|
|
|
$qb->setParameter('comparison_10', $this->values, $valueType)->shouldBeCalled(); |
56
|
|
|
|
57
|
|
|
$this->transform($qb, 'a')->shouldReturn(':comparison_10'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function it_is_transformable_pdo_type(QueryBuilder $qb, ArrayCollection $parameters) |
61
|
|
|
{ |
62
|
|
|
$valueType = \PDO::PARAM_INT; |
63
|
|
|
$this->beConstructedWith($this->values, $valueType); |
64
|
|
|
|
65
|
|
|
$qb->getParameters()->willReturn($parameters); |
66
|
|
|
$parameters->count()->willReturn(10); |
67
|
|
|
|
68
|
|
|
$qb->setParameter('comparison_10', $this->values, $valueType)->shouldBeCalled(); |
69
|
|
|
|
70
|
|
|
$this->transform($qb, 'a')->shouldReturn(':comparison_10'); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
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.