forked from schmittjoh/php-option
/
changes.patch
397 lines (357 loc) · 15.6 KB
/
changes.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
From 5c815dbd04e88fedb84eb6b7c531601a8a9c3866 Mon Sep 17 00:00:00 2001
From: Mark Carver <mark.carver@me.com>
Date: Wed, 7 Aug 2019 00:24:31 -0500
Subject: [PATCH] Update tests
Signed-off-by: Mark Carver <mark.carver@me.com>
---
tests/PhpOption/Tests/EnsureTest.php | 31 +++++++++++--
tests/PhpOption/Tests/LazyOptionTest.php | 41 +++++++++++++++---
tests/PhpOption/Tests/NoneTest.php | 20 ++++++++-
tests/PhpOption/Tests/OptionTest.php | 55 ++++++++++++++++++------
tests/PhpOption/Tests/SomeTest.php | 55 ++++++++++++++++++------
5 files changed, 165 insertions(+), 37 deletions(-)
mode change 100644 => 100755 tests/PhpOption/Tests/EnsureTest.php
mode change 100644 => 100755 tests/PhpOption/Tests/LazyOptionTest.php
mode change 100644 => 100755 tests/PhpOption/Tests/NoneTest.php
mode change 100644 => 100755 tests/PhpOption/Tests/OptionTest.php
mode change 100644 => 100755 tests/PhpOption/Tests/SomeTest.php
diff --git tests/PhpOption/Tests/EnsureTest.php tests/PhpOption/Tests/EnsureTest.php
old mode 100644
new mode 100755
index 6bd018f..ac9ed03
--- tests/PhpOption/Tests/EnsureTest.php
+++ tests/PhpOption/Tests/EnsureTest.php
@@ -1,22 +1,47 @@
<?php
+/**
+ * Copyright 2019 Mark Carver <mark.carver@me.com>
+ * Copyright 2012 Johannes M. Schmitt <schmittjoh@gmail.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
namespace PhpOption\Tests;
use PhpOption\None;
use PhpOption\Option;
use PhpOption\Some;
+use PHPUnit\Framework\TestCase;
/**
* Tests for Option::ensure() method
*
- * @covers Option::ensure
+ * @covers \PhpOption\Option::ensure
*/
-class EnsureTest extends \PHPUnit_Framework_TestCase
+class EnsureTest extends TestCase
{
protected function ensure($value, $noneValue = null)
{
$option = Option::ensure($value, $noneValue);
- $this->assertInstanceOf('PhpOption\Option', $option);
+ // Due to some weird bug in PHP 5.3, class_alias() doesn't work as expected.
+ // Instead, to make it work, the classes have to be extended which breaks inheritance.
+ // To get these tests working properly, the real class it's returning has to be verified.
+ if (PHP_MAJOR_VERSION === 5 && PHP_MINOR_VERSION === 3) {
+ $this->assertInstanceOf('UnicornFail\\PhpOption\\OptionInterface', $option);
+ } else {
+ $this->assertInstanceOf('PhpOption\\Option', $option);
+ }
return $option;
}
diff --git tests/PhpOption/Tests/LazyOptionTest.php tests/PhpOption/Tests/LazyOptionTest.php
old mode 100644
new mode 100755
index 30b1347..9d7020a
--- tests/PhpOption/Tests/LazyOptionTest.php
+++ tests/PhpOption/Tests/LazyOptionTest.php
@@ -1,10 +1,28 @@
<?php
+/**
+ * Copyright 2019 Mark Carver <mark.carver@me.com>
+ * Copyright 2012 Johannes M. Schmitt <schmittjoh@gmail.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
namespace PhpOption\Tests;
use PhpOption\LazyOption;
+use PHPUnit\Framework\TestCase;
-class LazyOptionTest extends \PHPUnit_Framework_TestCase
+class LazyOptionTest extends TestCase
{
private $subject;
@@ -106,7 +124,7 @@ class LazyOptionTest extends \PHPUnit_Framework_TestCase
/**
* @expectedException \RuntimeException
- * @expectedExceptionMessage Expected instance of \PhpOption\Option
+ * @expectedExceptionMessage Lazy option callbacks must return an instance of \UnicornFail\PhpOption\OptionInterface.
*/
public function testExceptionIsThrownIfCallbackReturnsNonOption()
{
@@ -121,8 +139,8 @@ class LazyOptionTest extends \PHPUnit_Framework_TestCase
}
/**
- * @expectedException InvalidArgumentException
- * @expectedExceptionMessage Invalid callback given
+ * @expectedException \UnicornFail\PhpOption\Exceptions\InvalidCallableException
+ * @expectedExceptionMessage Invalid callable "invalidCallback"
*/
public function testInvalidCallbackAndConstructor()
{
@@ -130,8 +148,8 @@ class LazyOptionTest extends \PHPUnit_Framework_TestCase
}
/**
- * @expectedException InvalidArgumentException
- * @expectedExceptionMessage Invalid callback given
+ * @expectedException \UnicornFail\PhpOption\Exceptions\InvalidCallableException
+ * @expectedExceptionMessage Invalid callable "invalidCallback"
*/
public function testInvalidCallbackAndCreate()
{
@@ -153,7 +171,16 @@ class LazyOptionTest extends \PHPUnit_Framework_TestCase
{
$called = false;
$self = $this;
- $this->assertInstanceOf('PhpOption\Some', LazyOption::fromValue('foo')->forAll(function($v) use (&$called, $self) {
+
+ // Due to some weird bug in PHP 5.3, class_alias() doesn't work as expected.
+ // Instead, to make it work, the classes have to be extended which breaks inheritance.
+ // To get these tests working properly, the real class it's returning has to be verified.
+ if (PHP_MAJOR_VERSION === 5 && PHP_MINOR_VERSION === 3) {
+ $class = 'UnicornFail\\PhpOption\\OptionInterface';
+ } else {
+ $class = 'PhpOption\\Some';
+ }
+ $this->assertInstanceOf($class, LazyOption::fromValue('foo')->forAll(function($v) use (&$called, $self) {
$called = true;
$self->assertEquals('foo', $v);
}));
diff --git tests/PhpOption/Tests/NoneTest.php tests/PhpOption/Tests/NoneTest.php
old mode 100644
new mode 100755
index 7ea644c..2a15aab
--- tests/PhpOption/Tests/NoneTest.php
+++ tests/PhpOption/Tests/NoneTest.php
@@ -1,10 +1,28 @@
<?php
+/**
+ * Copyright 2019 Mark Carver <mark.carver@me.com>
+ * Copyright 2012 Johannes M. Schmitt <schmittjoh@gmail.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
namespace PhpOption\Tests;
use PhpOption\None;
+use PHPUnit\Framework\TestCase;
-class NoneTest extends \PHPUnit_Framework_TestCase
+class NoneTest extends TestCase
{
private $none;
diff --git tests/PhpOption/Tests/OptionTest.php tests/PhpOption/Tests/OptionTest.php
old mode 100644
new mode 100755
index 1f59e1c..6652627
--- tests/PhpOption/Tests/OptionTest.php
+++ tests/PhpOption/Tests/OptionTest.php
@@ -1,33 +1,60 @@
<?php
+/**
+ * Copyright 2019 Mark Carver <mark.carver@me.com>
+ * Copyright 2012 Johannes M. Schmitt <schmittjoh@gmail.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
namespace PhpOption\Tests;
-use PhpOption\None;
use PhpOption\Option;
-use PhpOption\Some;
+use PHPUnit\Framework\TestCase;
-class OptionTest extends \PHPUnit_Framework_TestCase
+class OptionTest extends TestCase
{
+ protected function assertOptionInstance($expected, $actual) {
+ // Due to some weird bug in PHP 5.3, class_alias() doesn't work as expected.
+ // Instead, to make it work, the classes have to be extended which breaks inheritance.
+ // To get these tests working properly, the real class it's returning has to be verified.
+ if (PHP_MAJOR_VERSION === 5 && PHP_MINOR_VERSION === 3) {
+ $this->assertInstanceOf("UnicornFail\\$expected", $actual);
+ } else {
+ $this->assertInstanceOf($expected, $actual);
+ }
+
+ }
public function testfromValueWithDefaultNoneValue()
{
- $this->assertInstanceOf('PhpOption\None', \PhpOption\Option::fromValue(null));
- $this->assertInstanceOf('PhpOption\Some', \PhpOption\Option::fromValue('value'));
+ $this->assertOptionInstance('PhpOption\None', \PhpOption\Option::fromValue(null));
+ $this->assertOptionInstance('PhpOption\Some', \PhpOption\Option::fromValue('value'));
}
public function testFromValueWithFalseNoneValue()
{
- $this->assertInstanceOf('PhpOption\None', \PhpOption\Option::fromValue(false, false));
- $this->assertInstanceOf('PhpOption\Some', \PhpOption\Option::fromValue('value', false));
- $this->assertInstanceOf('PhpOption\Some', \PhpOption\Option::fromValue(null, false));
+ $this->assertOptionInstance('PhpOption\None', \PhpOption\Option::fromValue(false, false));
+ $this->assertOptionInstance('PhpOption\Some', \PhpOption\Option::fromValue('value', false));
+ $this->assertOptionInstance('PhpOption\Some', \PhpOption\Option::fromValue(null, false));
}
public function testFromArraysValue()
{
- $this->assertEquals(None::create(), Option::fromArraysValue('foo', 'bar'));
- $this->assertEquals(None::create(), Option::fromArraysValue(null, 'bar'));
- $this->assertEquals(None::create(), Option::fromArraysValue(array('foo' => 'bar'), 'baz'));
- $this->assertEquals(None::create(), Option::fromArraysValue(array('foo' => null), 'foo'));
- $this->assertEquals(new Some('foo'), Option::fromArraysValue(array('foo' => 'foo'), 'foo'));
+ $this->assertOptionInstance('PhpOption\None', Option::fromArraysValue('foo', 'bar'));
+ $this->assertOptionInstance('PhpOption\None', Option::fromArraysValue(null, 'bar'));
+ $this->assertOptionInstance('PhpOption\None', Option::fromArraysValue(array('foo' => 'bar'), 'baz'));
+ $this->assertOptionInstance('PhpOption\None', Option::fromArraysValue(array('foo' => null), 'foo'));
+ $this->assertOptionInstance('PhpOption\Some', Option::fromArraysValue(array('foo' => 'foo'), 'foo'));
}
public function testFromReturn()
@@ -78,4 +105,4 @@ class OptionTest extends \PHPUnit_Framework_TestCase
$this->assertEquals('foo', $a->orElse($returns)->orElse($throws)->get());
}
-}
\ No newline at end of file
+}
diff --git tests/PhpOption/Tests/SomeTest.php tests/PhpOption/Tests/SomeTest.php
old mode 100644
new mode 100755
index 33b5501..8bd807b
--- tests/PhpOption/Tests/SomeTest.php
+++ tests/PhpOption/Tests/SomeTest.php
@@ -1,11 +1,41 @@
<?php
+/**
+ * Copyright 2019 Mark Carver <mark.carver@me.com>
+ * Copyright 2012 Johannes M. Schmitt <schmittjoh@gmail.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
namespace PhpOption\Tests;
use PhpOption\Some;
+use PHPUnit\Framework\TestCase;
-class SomeTest extends \PHPUnit_Framework_TestCase
+class SomeTest extends TestCase
{
+ protected function assertOptionInstance($expected, $actual) {
+ // Due to some weird bug in PHP 5.3, class_alias() doesn't work as expected.
+ // Instead, to make it work, the classes have to be extended which breaks inheritance.
+ // To get these tests working properly, the real class it's returning has to be verified.
+ if (PHP_MAJOR_VERSION === 5 && PHP_MINOR_VERSION === 3) {
+ $this->assertInstanceOf("UnicornFail\\$expected", $actual);
+ } else {
+ $this->assertInstanceOf($expected, $actual);
+ }
+
+ }
+
public function testGet()
{
$some = new \PhpOption\Some('foo');
@@ -76,7 +106,7 @@ class SomeTest extends \PHPUnit_Framework_TestCase
{
$some = new Some('foo');
- $this->assertInstanceOf('PhpOption\None', $some->filter(function($v) { return 0 === strlen($v); }));
+ $this->assertOptionInstance('PhpOption\None', $some->filter(function($v) { return 0 === strlen($v); }));
$this->assertSame($some, $some->filter(function($v) { return strlen($v) > 0; }));
}
@@ -84,7 +114,7 @@ class SomeTest extends \PHPUnit_Framework_TestCase
{
$some = new Some('foo');
- $this->assertInstanceOf('PhpOption\None', $some->filterNot(function($v) { return strlen($v) > 0; }));
+ $this->assertOptionInstance('PhpOption\None', $some->filterNot(function($v) { return strlen($v) > 0; }));
$this->assertSame($some, $some->filterNot(function($v) { return strlen($v) === 0; }));
}
@@ -93,8 +123,8 @@ class SomeTest extends \PHPUnit_Framework_TestCase
$some = new Some('foo');
$this->assertSame($some, $some->select('foo'));
- $this->assertInstanceOf('PhpOption\None', $some->select('bar'));
- $this->assertInstanceOf('PhpOption\None', $some->select(true));
+ $this->assertOptionInstance('PhpOption\None', $some->select('bar'));
+ $this->assertOptionInstance('PhpOption\None', $some->select(true));
}
public function testReject()
@@ -103,23 +133,24 @@ class SomeTest extends \PHPUnit_Framework_TestCase
$this->assertSame($some, $some->reject(null));
$this->assertSame($some, $some->reject(true));
- $this->assertInstanceOf('PhpOption\None', $some->reject('foo'));
+ $this->assertOptionInstance('PhpOption\None', $some->reject('foo'));
}
public function testFoldLeftRight()
{
$some = new Some(5);
- $this->assertSame(6, $some->foldLeft(1, function($a, $b) {
- $this->assertEquals(1, $a);
- $this->assertEquals(5, $b);
+ $self = $this;
+ $this->assertSame(6, $some->foldLeft(1, function($a, $b) use ($self) {
+ $self->assertEquals(1, $a);
+ $self->assertEquals(5, $b);
return $a + $b;
}));
- $this->assertSame(6, $some->foldRight(1, function($a, $b) {
- $this->assertEquals(1, $b);
- $this->assertEquals(5, $a);
+ $this->assertSame(6, $some->foldRight(1, function($a, $b) use ($self) {
+ $self->assertEquals(1, $b);
+ $self->assertEquals(5, $a);
return $a + $b;
}));
--
2.22.0