SelectHiddenAsSpec::it_is_a_select_as()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
dl 4
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\Selection;
15
16
use Doctrine\Common\Collections\ArrayCollection;
17
use Doctrine\ORM\QueryBuilder;
18
use Happyr\DoctrineSpecification\Filter\Equals;
19
use Happyr\DoctrineSpecification\Operand\Field;
20
use Happyr\DoctrineSpecification\Operand\Value;
21
use Happyr\DoctrineSpecification\Query\Selection\SelectHiddenAs;
22
use Happyr\DoctrineSpecification\Query\Selection\Selection;
23
use PhpSpec\ObjectBehavior;
24
25
/**
26
 * @mixin SelectHiddenAs
27
 */
28 View Code Duplication
class SelectHiddenAsSpec extends ObjectBehavior
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

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.

Loading history...
29
{
30
    private $field = 'foo';
31
32
    private $alias = 'bar';
33
34
    public function let()
35
    {
36
        $this->beConstructedWith($this->field, $this->alias);
37
    }
38
39
    public function it_is_a_select_as()
40
    {
41
        $this->shouldBeAnInstanceOf(SelectHiddenAs::class);
42
    }
43
44
    public function it_is_a_selection()
45
    {
46
        $this->shouldBeAnInstanceOf(Selection::class);
47
    }
48
49
    public function it_is_transformable(QueryBuilder $qb)
50
    {
51
        $dqlAlias = 'a';
52
        $expression = '(a.foo) AS HIDDEN bar';
53
54
        $this->transform($qb, $dqlAlias)->shouldReturn($expression);
55
    }
56
57
    public function it_is_transformable_field(QueryBuilder $qb)
58
    {
59
        $dqlAlias = 'a';
60
        $expression = '(a.foo) AS HIDDEN bar';
61
        $field = new Field('foo');
62
63
        $this->beConstructedWith($field, $this->alias);
64
        $this->transform($qb, $dqlAlias)->shouldReturn($expression);
65
    }
66
67
    public function it_is_transformable_value(QueryBuilder $qb, ArrayCollection $parameters)
68
    {
69
        $dqlAlias = 'a';
70
        $expression = '(:comparison_10) AS HIDDEN bar';
71
        $value = new Value('foo');
72
73
        $this->beConstructedWith($value, $this->alias);
74
75
        $qb->getParameters()->willReturn($parameters);
76
        $parameters->count()->willReturn(10);
77
78
        $qb->setParameter('comparison_10', 'foo', null)->shouldBeCalled();
79
80
        $this->transform($qb, $dqlAlias)->shouldReturn($expression);
81
    }
82
83
    public function it_is_transformable_filter(QueryBuilder $qb, ArrayCollection $parameters)
84
    {
85
        $dqlAlias = 'a';
86
        $expression = '(a.foo = :comparison_10) AS HIDDEN bar';
87
        $filter = new Equals('foo', 'bar');
88
89
        $this->beConstructedWith($filter, $this->alias);
90
91
        $qb->getParameters()->willReturn($parameters);
92
        $parameters->count()->willReturn(10);
93
94
        $qb->setParameter('comparison_10', 'bar', null)->shouldBeCalled();
95
96
        $this->transform($qb, $dqlAlias)->shouldReturn($expression);
97
    }
98
}
99