Completed
Push — 1.0 ( 75b22b...f155d9 )
by Peter
15:56 queued 05:56
created

SelectHiddenAsSpec::it_is_transformable_value()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 15
Ratio 100 %

Importance

Changes 0
Metric Value
dl 15
loc 15
rs 9.7666
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace tests\Happyr\DoctrineSpecification\Query\Selection;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\ORM\QueryBuilder;
7
use Happyr\DoctrineSpecification\Filter\Equals;
8
use Happyr\DoctrineSpecification\Operand\Field;
9
use Happyr\DoctrineSpecification\Operand\Value;
10
use Happyr\DoctrineSpecification\Query\Selection\SelectHiddenAs;
11
use PhpSpec\ObjectBehavior;
12
13
/**
14
 * @mixin SelectHiddenAs
15
 */
16 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...
17
{
18
    private $field = 'foo';
19
20
    private $alias = 'bar';
21
22
    public function let()
23
    {
24
        $this->beConstructedWith($this->field, $this->alias);
25
    }
26
27
    public function it_is_a_select_as()
28
    {
29
        $this->shouldBeAnInstanceOf('Happyr\DoctrineSpecification\Query\Selection\SelectHiddenAs');
30
    }
31
32
    public function it_is_a_selection()
33
    {
34
        $this->shouldBeAnInstanceOf('Happyr\DoctrineSpecification\Query\Selection\Selection');
35
    }
36
37
    public function it_is_transformable(QueryBuilder $qb)
38
    {
39
        $dqlAlias = 'a';
40
        $expression = '(a.foo) AS HIDDEN bar';
41
42
        $this->transform($qb, $dqlAlias)->shouldReturn($expression);
43
    }
44
45
    public function it_is_transformable_field(QueryBuilder $qb)
46
    {
47
        $dqlAlias = 'a';
48
        $expression = '(a.foo) AS HIDDEN bar';
49
        $field = new Field('foo');
50
51
        $this->beConstructedWith($field, $this->alias);
52
        $this->transform($qb, $dqlAlias)->shouldReturn($expression);
53
    }
54
55
    public function it_is_transformable_value(QueryBuilder $qb, ArrayCollection $parameters)
56
    {
57
        $dqlAlias = 'a';
58
        $expression = '(:comparison_10) AS HIDDEN bar';
59
        $value = new Value('foo');
60
61
        $this->beConstructedWith($value, $this->alias);
62
63
        $qb->getParameters()->willReturn($parameters);
64
        $parameters->count()->willReturn(10);
65
66
        $qb->setParameter('comparison_10', 'foo', null)->shouldBeCalled();
67
68
        $this->transform($qb, $dqlAlias)->shouldReturn($expression);
69
    }
70
71
    public function it_is_transformable_filter(QueryBuilder $qb, ArrayCollection $parameters)
72
    {
73
        $dqlAlias = 'a';
74
        $expression = '(a.foo = :comparison_10) AS HIDDEN bar';
75
        $filter = new Equals('foo', 'bar');
76
77
        $this->beConstructedWith($filter, $this->alias);
78
79
        $qb->getParameters()->willReturn($parameters);
80
        $parameters->count()->willReturn(10);
81
82
        $qb->setParameter('comparison_10', 'bar', null)->shouldBeCalled();
83
84
        $this->transform($qb, $dqlAlias)->shouldReturn($expression);
85
    }
86
}
87