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\Operand\PlatformFunction; |
16
|
|
|
|
17
|
|
|
use Doctrine\ORM\QueryBuilder; |
18
|
|
|
use Happyr\DoctrineSpecification\Operand\PlatformFunction\Trim; |
19
|
|
|
use PhpSpec\ObjectBehavior; |
20
|
|
|
use tests\Happyr\DoctrineSpecification\Player; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @mixin Trim |
24
|
|
|
*/ |
25
|
|
|
final class TrimSpec extends ObjectBehavior |
26
|
|
|
{ |
27
|
|
|
public function it_should_transform(QueryBuilder $qb): void |
28
|
|
|
{ |
29
|
|
|
$this->beConstructedWith('foo'); |
30
|
|
|
|
31
|
|
|
$context = 'a'; |
32
|
|
|
|
33
|
|
|
$this->transform($qb, $context)->shouldReturn('TRIM(a.foo)'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
View Code Duplication |
public function it_should_transform_leading(QueryBuilder $qb): void |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
$this->beConstructedWith('foo', Trim::LEADING); |
39
|
|
|
|
40
|
|
|
$context = 'a'; |
41
|
|
|
|
42
|
|
|
$this->transform($qb, $context)->shouldReturn('TRIM(LEADING FROM a.foo)'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
View Code Duplication |
public function it_should_transform_trailing(QueryBuilder $qb): void |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
$this->beConstructedWith('foo', Trim::TRAILING); |
48
|
|
|
|
49
|
|
|
$context = 'a'; |
50
|
|
|
|
51
|
|
|
$this->transform($qb, $context)->shouldReturn('TRIM(TRAILING FROM a.foo)'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
View Code Duplication |
public function it_should_transform_both(QueryBuilder $qb): void |
|
|
|
|
55
|
|
|
{ |
56
|
|
|
$this->beConstructedWith('foo', Trim::BOTH); |
57
|
|
|
|
58
|
|
|
$context = 'a'; |
59
|
|
|
|
60
|
|
|
$this->transform($qb, $context)->shouldReturn('TRIM(BOTH FROM a.foo)'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
View Code Duplication |
public function it_should_transform_with_characters(QueryBuilder $qb): void |
|
|
|
|
64
|
|
|
{ |
65
|
|
|
$this->beConstructedWith('foo', '', 's'); |
66
|
|
|
|
67
|
|
|
$context = 'a'; |
68
|
|
|
|
69
|
|
|
$this->transform($qb, $context)->shouldReturn('TRIM(\'s\' FROM a.foo)'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
View Code Duplication |
public function it_should_transform_leading_with_characters(QueryBuilder $qb): void |
|
|
|
|
73
|
|
|
{ |
74
|
|
|
$this->beConstructedWith('foo', Trim::LEADING, 's'); |
75
|
|
|
|
76
|
|
|
$context = 'a'; |
77
|
|
|
|
78
|
|
|
$this->transform($qb, $context)->shouldReturn('TRIM(LEADING \'s\' FROM a.foo)'); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
View Code Duplication |
public function it_should_transform_trailing_with_characters(QueryBuilder $qb): void |
|
|
|
|
82
|
|
|
{ |
83
|
|
|
$this->beConstructedWith('foo', Trim::TRAILING, 's'); |
84
|
|
|
|
85
|
|
|
$context = 'a'; |
86
|
|
|
|
87
|
|
|
$this->transform($qb, $context)->shouldReturn('TRIM(TRAILING \'s\' FROM a.foo)'); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
View Code Duplication |
public function it_should_transform_both_with_characters(QueryBuilder $qb): void |
|
|
|
|
91
|
|
|
{ |
92
|
|
|
$this->beConstructedWith('foo', Trim::BOTH, 's'); |
93
|
|
|
|
94
|
|
|
$context = 'a'; |
95
|
|
|
|
96
|
|
|
$this->transform($qb, $context)->shouldReturn('TRIM(BOTH \'s\' FROM a.foo)'); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function it_should_execute(): void |
100
|
|
|
{ |
101
|
|
|
$this->beConstructedWith('pseudo'); |
102
|
|
|
|
103
|
|
|
$player = new Player(' Moe ', 'M', 1230); |
104
|
|
|
|
105
|
|
|
$this->execute($player)->shouldReturn('Moe'); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function it_should_execute_leading(): void |
109
|
|
|
{ |
110
|
|
|
$this->beConstructedWith('pseudo', Trim::LEADING); |
111
|
|
|
|
112
|
|
|
$player = new Player(' Moe ', 'M', 1230); |
113
|
|
|
|
114
|
|
|
$this->execute($player)->shouldReturn('Moe '); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function it_should_execute_trailing(): void |
118
|
|
|
{ |
119
|
|
|
$this->beConstructedWith('pseudo', Trim::TRAILING); |
120
|
|
|
|
121
|
|
|
$player = new Player(' Moe ', 'M', 1230); |
122
|
|
|
|
123
|
|
|
$this->execute($player)->shouldReturn(' Moe'); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function it_should_execute_both(): void |
127
|
|
|
{ |
128
|
|
|
$this->beConstructedWith('pseudo', Trim::BOTH); |
129
|
|
|
|
130
|
|
|
$player = new Player(' Moe ', 'M', 1230); |
131
|
|
|
|
132
|
|
|
$this->execute($player)->shouldReturn('Moe'); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
public function it_should_execute_with_characters(): void |
136
|
|
|
{ |
137
|
|
|
$this->beConstructedWith('pseudo', '', '$'); |
138
|
|
|
|
139
|
|
|
$player = new Player('$Moe$', 'M', 1230); |
140
|
|
|
|
141
|
|
|
$this->execute($player)->shouldReturn('Moe'); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function it_should_execute_leading_with_characters(): void |
145
|
|
|
{ |
146
|
|
|
$this->beConstructedWith('pseudo', Trim::LEADING, '$'); |
147
|
|
|
|
148
|
|
|
$player = new Player('$Moe$', 'M', 1230); |
149
|
|
|
|
150
|
|
|
$this->execute($player)->shouldReturn('Moe$'); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
public function it_should_execute_trailing_with_characters(): void |
154
|
|
|
{ |
155
|
|
|
$this->beConstructedWith('pseudo', Trim::TRAILING, '$'); |
156
|
|
|
|
157
|
|
|
$player = new Player('$Moe$', 'M', 1230); |
158
|
|
|
|
159
|
|
|
$this->execute($player)->shouldReturn('$Moe'); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
public function it_should_execute_both_with_characters(): void |
163
|
|
|
{ |
164
|
|
|
$this->beConstructedWith('pseudo', Trim::BOTH, '$'); |
165
|
|
|
|
166
|
|
|
$player = new Player('$Moe$', 'M', 1230); |
167
|
|
|
|
168
|
|
|
$this->execute($player)->shouldReturn('Moe'); |
169
|
|
|
} |
170
|
|
|
} |
171
|
|
|
|
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.