Completed
Push — 1.0 ( f155d9...8e07ac )
by Peter
08:03
created

PlatformFunctionSpec::it_is_a_platform_function()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace tests\Happyr\DoctrineSpecification\Operand;
4
5
use Doctrine\ORM\Configuration;
6
use Doctrine\ORM\EntityManagerInterface;
7
use Doctrine\ORM\QueryBuilder;
8
use Happyr\DoctrineSpecification\Operand\Field;
9
use Happyr\DoctrineSpecification\Operand\PlatformFunction;
10
use PhpSpec\ObjectBehavior;
11
12
/**
13
 * @mixin PlatformFunction
14
 */
15
class PlatformFunctionSpec extends ObjectBehavior
16
{
17
    private $functionName = 'UPPER';
18
19
    private $arguments = 'foo';
20
21
    public function let()
22
    {
23
        $this->beConstructedWith($this->functionName, $this->arguments);
24
    }
25
26
    public function it_is_a_platform_function()
27
    {
28
        $this->shouldBeAnInstanceOf('Happyr\DoctrineSpecification\Operand\PlatformFunction');
29
    }
30
31
    public function it_is_a_operand()
32
    {
33
        $this->shouldBeAnInstanceOf('Happyr\DoctrineSpecification\Operand\Operand');
34
    }
35
36
    public function it_is_transformable_doctrine_function(QueryBuilder $qb)
37
    {
38
        $dqlAlias = 'a';
39
        $expression = 'UPPER(a.foo)';
40
41
        $this->transform($qb, $dqlAlias)->shouldReturn($expression);
42
    }
43
44
    public function it_is_transformable_many_arguments(QueryBuilder $qb)
45
    {
46
        $dqlAlias = 'a';
47
        $expression = 'concat(a.foo, a.bar)';
48
49
        $this->beConstructedWith('concat', new Field('foo'), new Field('bar'));
50
51
        $this->transform($qb, $dqlAlias)->shouldReturn($expression);
52
    }
53
54 View Code Duplication
    public function it_is_transformable_custom_string_function(
0 ignored issues
show
Duplication introduced by
This method 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...
55
        QueryBuilder $qb,
56
        EntityManagerInterface $em,
57
        Configuration $configuration
58
    ) {
59
        $dqlAlias = 'a';
60
        $functionName = 'foo';
61
        $expression = 'foo(a.foo)';
62
63
        $qb->getEntityManager()->willReturn($em);
64
        $em->getConfiguration()->willReturn($configuration);
65
        $configuration->getCustomStringFunction($functionName)->willReturn('ToStringClass');
66
        $configuration->getCustomNumericFunction($functionName)->willReturn(null);
67
        $configuration->getCustomDatetimeFunction($functionName)->willReturn(null);
68
69
        $this->beConstructedWith($functionName, 'foo');
70
71
        $this->transform($qb, $dqlAlias)->shouldReturn($expression);
72
    }
73
74 View Code Duplication
    public function it_is_transformable_custom_numeric_function(
0 ignored issues
show
Duplication introduced by
This method 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...
75
        QueryBuilder $qb,
76
        EntityManagerInterface $em,
77
        Configuration $configuration
78
    ) {
79
        $dqlAlias = 'a';
80
        $functionName = 'foo';
81
        $expression = 'foo(a.foo)';
82
83
        $qb->getEntityManager()->willReturn($em);
84
        $em->getConfiguration()->willReturn($configuration);
85
        $configuration->getCustomStringFunction($functionName)->willReturn(null);
86
        $configuration->getCustomNumericFunction($functionName)->willReturn('ToNumericClass');
87
        $configuration->getCustomDatetimeFunction($functionName)->willReturn(null);
88
89
        $this->beConstructedWith($functionName, 'foo');
90
91
        $this->transform($qb, $dqlAlias)->shouldReturn($expression);
92
    }
93
94 View Code Duplication
    public function it_is_transformable_custom_datetime_function(
0 ignored issues
show
Duplication introduced by
This method 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...
95
        QueryBuilder $qb,
96
        EntityManagerInterface $em,
97
        Configuration $configuration
98
    ) {
99
        $dqlAlias = 'a';
100
        $functionName = 'foo';
101
        $expression = 'foo(a.foo)';
102
103
        $qb->getEntityManager()->willReturn($em);
104
        $em->getConfiguration()->willReturn($configuration);
105
        $configuration->getCustomStringFunction($functionName)->willReturn(null);
106
        $configuration->getCustomNumericFunction($functionName)->willReturn(null);
107
        $configuration->getCustomDatetimeFunction($functionName)->willReturn('ToDatetimeClass');
108
109
        $this->beConstructedWith($functionName, 'foo');
110
111
        $this->transform($qb, $dqlAlias)->shouldReturn($expression);
112
    }
113
114
    public function it_is_transformable_undefined_function(
115
        QueryBuilder $qb,
116
        EntityManagerInterface $em,
117
        Configuration $configuration
118
    ) {
119
        $functionName = 'foo';
120
121
        $qb->getEntityManager()->willReturn($em);
122
        $em->getConfiguration()->willReturn($configuration);
123
        $configuration->getCustomStringFunction($functionName)->willReturn(null);
124
        $configuration->getCustomNumericFunction($functionName)->willReturn(null);
125
        $configuration->getCustomDatetimeFunction($functionName)->willReturn(null);
126
127
        $this->beConstructedWith($functionName, 'foo');
128
        $this->shouldThrow('Happyr\DoctrineSpecification\Exception\InvalidArgumentException')
129
            ->during('transform', array($qb, 'a'));
130
    }
131
132
    public function it_is_transformable_not_convertible(QueryBuilder $qb)
133
    {
134
        $this->beConstructedWith('concat', ['foo', 'bar', 'baz']);
135
136
        $this->shouldThrow('Happyr\DoctrineSpecification\Exception\NotConvertibleException')
137
            ->during('transform', array($qb, 'a'));
138
    }
139
}
140