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; |
16
|
|
|
|
17
|
|
|
use Happyr\DoctrineSpecification\Filter\MemberOfX; |
18
|
|
|
use Happyr\DoctrineSpecification\Logic\LogicX; |
19
|
|
|
use Happyr\DoctrineSpecification\Operand\Addition; |
20
|
|
|
use Happyr\DoctrineSpecification\Operand\Alias; |
21
|
|
|
use Happyr\DoctrineSpecification\Operand\CountDistinct; |
22
|
|
|
use Happyr\DoctrineSpecification\Operand\Division; |
23
|
|
|
use Happyr\DoctrineSpecification\Operand\Modulo; |
24
|
|
|
use Happyr\DoctrineSpecification\Operand\Multiplication; |
25
|
|
|
use Happyr\DoctrineSpecification\Operand\PlatformFunction; |
26
|
|
|
use Happyr\DoctrineSpecification\Operand\Subtraction; |
27
|
|
|
use Happyr\DoctrineSpecification\Query\AddSelect; |
28
|
|
|
use Happyr\DoctrineSpecification\Query\Distinct; |
29
|
|
|
use Happyr\DoctrineSpecification\Query\Select; |
30
|
|
|
use Happyr\DoctrineSpecification\Query\Selection\SelectAs; |
31
|
|
|
use Happyr\DoctrineSpecification\Query\Selection\SelectEntity; |
32
|
|
|
use Happyr\DoctrineSpecification\Query\Selection\SelectHiddenAs; |
33
|
|
|
use Happyr\DoctrineSpecification\Spec; |
34
|
|
|
use PhpSpec\ObjectBehavior; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @mixin Spec |
38
|
|
|
*/ |
39
|
|
|
final class SpecSpec extends ObjectBehavior |
40
|
|
|
{ |
41
|
|
|
public function it_creates_an_x_specification(): void |
42
|
|
|
{ |
43
|
|
|
$this->andX()->shouldReturnAnInstanceOf(LogicX::class); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function it_creates_distinct(): void |
47
|
|
|
{ |
48
|
|
|
$this->distinct()->shouldReturnAnInstanceOf(Distinct::class); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function it_creates_count_distinct(): void |
52
|
|
|
{ |
53
|
|
|
$this->countDistinct('foo')->shouldReturnAnInstanceOf(CountDistinct::class); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function it_creates_add_operand(): void |
57
|
|
|
{ |
58
|
|
|
$this->add('foo', 'bar')->shouldReturnAnInstanceOf(Addition::class); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function it_creates_sub_operand(): void |
62
|
|
|
{ |
63
|
|
|
$this->sub('foo', 'bar')->shouldReturnAnInstanceOf(Subtraction::class); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function it_creates_mul_operand(): void |
67
|
|
|
{ |
68
|
|
|
$this->mul('foo', 'bar')->shouldReturnAnInstanceOf(Multiplication::class); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function it_creates_div_operand(): void |
72
|
|
|
{ |
73
|
|
|
$this->div('foo', 'bar')->shouldReturnAnInstanceOf(Division::class); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function it_creates_an_function(): void |
77
|
|
|
{ |
78
|
|
|
$this->fun('UPPER', 'arg')->shouldReturnAnInstanceOf(PlatformFunction::class); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function it_creates_an_function_with_many_args(): void |
82
|
|
|
{ |
83
|
|
|
$this->fun('CONCAT', 'a', 'b')->shouldReturnAnInstanceOf(PlatformFunction::class); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function it_creates_an_function_with_many_args_as_array(): void |
87
|
|
|
{ |
88
|
|
|
$this->fun('CONCAT', ['a', 'b'])->shouldReturnAnInstanceOf(PlatformFunction::class); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function it_creates_an_magic_function(): void |
92
|
|
|
{ |
93
|
|
|
$this->__callStatic('UPPER', ['arg'])->shouldReturnAnInstanceOf(PlatformFunction::class); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function it_creates_an_magic_function_many_args(): void |
97
|
|
|
{ |
98
|
|
|
$this->__callStatic('CONCAT', ['a', 'b'])->shouldReturnAnInstanceOf(PlatformFunction::class); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function it_creates_an_magic_function_many_args_inner(): void |
102
|
|
|
{ |
103
|
|
|
$this->__callStatic('CONCAT', [['a', 'b']])->shouldReturnAnInstanceOf(PlatformFunction::class); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function it_creates_select_query_modifier(): void |
107
|
|
|
{ |
108
|
|
|
$this->select('foo')->shouldReturnAnInstanceOf(Select::class); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function it_creates_add_select_query_modifier(): void |
112
|
|
|
{ |
113
|
|
|
$this->addSelect('foo')->shouldReturnAnInstanceOf(AddSelect::class); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function it_creates_select_entity_selection(): void |
117
|
|
|
{ |
118
|
|
|
$this->selectEntity('u')->shouldReturnAnInstanceOf(SelectEntity::class); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function it_creates_select_as_selection(): void |
122
|
|
|
{ |
123
|
|
|
$this->selectAs('foo', 'bar')->shouldReturnAnInstanceOf(SelectAs::class); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function it_creates_select_hidden_as_selection(): void |
127
|
|
|
{ |
128
|
|
|
$this->selectHiddenAs('foo', 'bar')->shouldReturnAnInstanceOf(SelectHiddenAs::class); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function it_creates_alias_operand(): void |
132
|
|
|
{ |
133
|
|
|
$this->alias('foo')->shouldReturnAnInstanceOf(Alias::class); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function it_creates_member_of_filter(): void |
137
|
|
|
{ |
138
|
|
|
$this->memberOfX('foo', 'bar')->shouldReturnAnInstanceOf(MemberOfX::class); |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|