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\Operand; |
15
|
|
|
|
16
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
17
|
|
|
use Doctrine\DBAL\Types\Type; |
18
|
|
|
use Doctrine\ORM\QueryBuilder; |
19
|
|
|
use Happyr\DoctrineSpecification\Operand\Operand; |
20
|
|
|
use Happyr\DoctrineSpecification\Operand\Value; |
21
|
|
|
use PhpSpec\ObjectBehavior; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @mixin Value |
25
|
|
|
*/ |
26
|
|
View Code Duplication |
class ValueSpec extends ObjectBehavior |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
private $value = 'foo'; |
29
|
|
|
|
30
|
|
|
private $valueType = null; |
31
|
|
|
|
32
|
|
|
public function let() |
33
|
|
|
{ |
34
|
|
|
$this->beConstructedWith($this->value, $this->valueType); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function it_is_a_value() |
38
|
|
|
{ |
39
|
|
|
$this->shouldBeAnInstanceOf(Value::class); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function it_is_a_operand() |
43
|
|
|
{ |
44
|
|
|
$this->shouldBeAnInstanceOf(Operand::class); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function it_is_transformable(QueryBuilder $qb, ArrayCollection $parameters) |
48
|
|
|
{ |
49
|
|
|
$dqlAlias = 'a'; |
50
|
|
|
|
51
|
|
|
$qb->getParameters()->willReturn($parameters); |
52
|
|
|
$parameters->count()->willReturn(10); |
53
|
|
|
|
54
|
|
|
$qb->setParameter('comparison_10', $this->value, $this->valueType)->shouldBeCalled(); |
55
|
|
|
|
56
|
|
|
$this->transform($qb, $dqlAlias)->shouldReturn(':comparison_10'); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function it_is_transformable_dbal_type(QueryBuilder $qb, ArrayCollection $parameters) |
60
|
|
|
{ |
61
|
|
|
$valueType = Type::DATE; |
|
|
|
|
62
|
|
|
$this->beConstructedWith($this->value, $valueType); |
63
|
|
|
|
64
|
|
|
$qb->getParameters()->willReturn($parameters); |
65
|
|
|
$parameters->count()->willReturn(10); |
66
|
|
|
|
67
|
|
|
$qb->setParameter('comparison_10', $this->value, $valueType)->shouldBeCalled(); |
68
|
|
|
|
69
|
|
|
$this->transform($qb, 'a')->shouldReturn(':comparison_10'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function it_is_transformable_pdo_type(QueryBuilder $qb, ArrayCollection $parameters) |
73
|
|
|
{ |
74
|
|
|
$valueType = \PDO::PARAM_INT; |
75
|
|
|
$this->beConstructedWith($this->value, $valueType); |
76
|
|
|
|
77
|
|
|
$qb->getParameters()->willReturn($parameters); |
78
|
|
|
$parameters->count()->willReturn(10); |
79
|
|
|
|
80
|
|
|
$qb->setParameter('comparison_10', $this->value, $valueType)->shouldBeCalled(); |
81
|
|
|
|
82
|
|
|
$this->transform($qb, 'a')->shouldReturn(':comparison_10'); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
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.