|
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\Query; |
|
16
|
|
|
|
|
17
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
18
|
|
|
use Doctrine\ORM\QueryBuilder; |
|
19
|
|
|
use Happyr\DoctrineSpecification\Operand\Addition; |
|
20
|
|
|
use Happyr\DoctrineSpecification\Operand\Field; |
|
21
|
|
|
use Happyr\DoctrineSpecification\Operand\Value; |
|
22
|
|
|
use Happyr\DoctrineSpecification\Query\QueryModifier; |
|
23
|
|
|
use Happyr\DoctrineSpecification\Query\SelectNew; |
|
24
|
|
|
use PhpSpec\ObjectBehavior; |
|
25
|
|
|
use tests\Happyr\DoctrineSpecification\Player; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @mixin SelectNew |
|
29
|
|
|
*/ |
|
30
|
|
|
final class SelectNewSpec extends ObjectBehavior |
|
31
|
|
|
{ |
|
32
|
|
|
public function let(): void |
|
33
|
|
|
{ |
|
34
|
|
|
$this->beConstructedWith(Player::class); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function it_is_a_select_new(): void |
|
38
|
|
|
{ |
|
39
|
|
|
$this->shouldBeAnInstanceOf(SelectNew::class); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function it_is_a_query_modifier(): void |
|
43
|
|
|
{ |
|
44
|
|
|
$this->shouldHaveType(QueryModifier::class); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function it_select_empty_object(QueryBuilder $qb): void |
|
48
|
|
|
{ |
|
49
|
|
|
$qb->select(sprintf('NEW %s()', Player::class))->shouldBeCalled(); |
|
50
|
|
|
|
|
51
|
|
|
$this->modify($qb, 'a'); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function it_select_with_field(QueryBuilder $qb): void |
|
55
|
|
|
{ |
|
56
|
|
|
$this->beConstructedWith(Player::class, 'pseudo'); |
|
57
|
|
|
|
|
58
|
|
|
$qb->select(sprintf('NEW %s(a.pseudo)', Player::class))->shouldBeCalled(); |
|
59
|
|
|
|
|
60
|
|
|
$this->modify($qb, 'a'); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function it_select_with_field_and_value(QueryBuilder $qb, ArrayCollection $parameters): void |
|
64
|
|
|
{ |
|
65
|
|
|
$this->beConstructedWith(Player::class, 'pseudo', 'F'); |
|
66
|
|
|
|
|
67
|
|
|
$qb->getParameters()->willReturn($parameters); |
|
68
|
|
|
$parameters->count()->willReturn(10); |
|
69
|
|
|
|
|
70
|
|
|
$qb->setParameter('comparison_10', 'F', null)->shouldBeCalled(); |
|
71
|
|
|
$qb->select(sprintf('NEW %s(a.pseudo, :comparison_10)', Player::class))->shouldBeCalled(); |
|
72
|
|
|
|
|
73
|
|
|
$this->modify($qb, 'a'); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function it_select_with_operands(QueryBuilder $qb, ArrayCollection $parameters): void |
|
77
|
|
|
{ |
|
78
|
|
|
$this->beConstructedWith( |
|
79
|
|
|
Player::class, |
|
80
|
|
|
new Field('pseudo'), |
|
81
|
|
|
new Value('F'), |
|
82
|
|
|
new Addition(new Field('foo'), new Field('bar')) |
|
83
|
|
|
); |
|
84
|
|
|
|
|
85
|
|
|
$qb->getParameters()->willReturn($parameters); |
|
86
|
|
|
$parameters->count()->willReturn(10); |
|
87
|
|
|
|
|
88
|
|
|
$qb->setParameter('comparison_10', 'F', null)->shouldBeCalled(); |
|
89
|
|
|
$qb->select(sprintf('NEW %s(a.pseudo, :comparison_10, (a.foo + a.bar))', Player::class))->shouldBeCalled(); |
|
90
|
|
|
|
|
91
|
|
|
$this->modify($qb, 'a'); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|