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\Query; |
15
|
|
|
|
16
|
|
|
use Doctrine\ORM\QueryBuilder; |
17
|
|
|
use Happyr\DoctrineSpecification\Operand\Field; |
18
|
|
|
use Happyr\DoctrineSpecification\Query\AddSelect; |
19
|
|
|
use Happyr\DoctrineSpecification\Query\QueryModifier; |
20
|
|
|
use PhpSpec\ObjectBehavior; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @mixin AddSelect |
24
|
|
|
*/ |
25
|
|
View Code Duplication |
class AddSelectSpec extends ObjectBehavior |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
public function let() |
28
|
|
|
{ |
29
|
|
|
$this->beConstructedWith('foo'); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function it_is_a_add_select() |
33
|
|
|
{ |
34
|
|
|
$this->shouldBeAnInstanceOf(AddSelect::class); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function it_is_a_specification() |
38
|
|
|
{ |
39
|
|
|
$this->shouldHaveType(QueryModifier::class); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function it_add_select_single_filed(QueryBuilder $qb) |
43
|
|
|
{ |
44
|
|
|
$qb->addSelect(['a.foo'])->shouldBeCalled(); |
45
|
|
|
$this->modify($qb, 'a'); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function it_add_select_several_fields(QueryBuilder $qb) |
49
|
|
|
{ |
50
|
|
|
$this->beConstructedWith('foo', 'bar'); |
51
|
|
|
$qb->addSelect(['b.foo', 'b.bar'])->shouldBeCalled(); |
52
|
|
|
$this->modify($qb, 'b'); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function it_add_select_several_fields_as_array(QueryBuilder $qb) |
56
|
|
|
{ |
57
|
|
|
$this->beConstructedWith(['foo', 'bar']); |
58
|
|
|
$qb->addSelect(['b.foo', 'b.bar'])->shouldBeCalled(); |
59
|
|
|
$this->modify($qb, 'b'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function it_add_select_operand(QueryBuilder $qb) |
63
|
|
|
{ |
64
|
|
|
$this->beConstructedWith('foo', new Field('bar')); |
65
|
|
|
$qb->addSelect(['b.foo', 'b.bar'])->shouldBeCalled(); |
66
|
|
|
$this->modify($qb, 'b'); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
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.