1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Part of SplTypes package. |
5
|
|
|
* |
6
|
|
|
* (c) Adrien Loyant <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Ducks\Component\SplTypes\Tests\phpunit; |
15
|
|
|
|
16
|
|
|
use Ducks\Component\SplTypes\Tests\common\Month; |
17
|
|
|
use PHPUnit\Framework\TestCase; |
18
|
|
|
|
19
|
|
|
class SplEnumTest extends TestCase |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Unit test. |
23
|
|
|
* |
24
|
|
|
* @return void |
25
|
|
|
*/ |
26
|
|
|
public function test(): void |
27
|
|
|
{ |
28
|
|
|
$instance = new Month(); |
29
|
|
|
$this->assertEquals(Month::__default, $instance()); |
30
|
|
|
|
31
|
|
|
$instance = new Month(Month::SEPTEMBER); |
32
|
|
|
$this->assertEquals(Month::SEPTEMBER, $instance()); |
33
|
|
|
|
34
|
|
|
$instance = new Month('1', false); |
35
|
|
|
$this->assertEquals(Month::JANUARY, $instance()); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Unit test. |
40
|
|
|
* |
41
|
|
|
* @throws \UnexpectedValueException |
42
|
|
|
* |
43
|
|
|
* @return void |
44
|
|
|
*/ |
45
|
|
|
public function testUnexpectedValueRxception(): void |
46
|
|
|
{ |
47
|
|
|
$this->expectException(\UnexpectedValueException::class); |
48
|
|
|
new Month('1'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Unit test. |
53
|
|
|
* |
54
|
|
|
* @return void |
55
|
|
|
*/ |
56
|
|
|
public function testGetConstList(): void |
57
|
|
|
{ |
58
|
|
|
$list = [ |
59
|
|
|
'__default' => 1, |
60
|
|
|
'JANUARY' => 1, |
61
|
|
|
'FEBRUARY' => 2, |
62
|
|
|
'MARCH' => 3, |
63
|
|
|
'APRIL' => 4, |
64
|
|
|
'MAY' => 5, |
65
|
|
|
'JUNE' => 6, |
66
|
|
|
'JULY' => 7, |
67
|
|
|
'AUGUST' => 8, |
68
|
|
|
'SEPTEMBER' => 9, |
69
|
|
|
'OCTOBER' => 10, |
70
|
|
|
'NOVEMBER' => 11, |
71
|
|
|
'DECEMBER' => 12, |
72
|
|
|
]; |
73
|
|
|
$instance = new Month(); |
74
|
|
|
|
75
|
|
|
$test = $instance->getConstList(true); |
76
|
|
|
$this->assertSame($list, $test); |
77
|
|
|
|
78
|
|
|
$test = $instance->getConstList(); |
79
|
|
|
unset($list['__default']); |
80
|
|
|
$this->assertSame($list, $test); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Unit test. |
85
|
|
|
* |
86
|
|
|
* @return void |
87
|
|
|
*/ |
88
|
|
|
public function testSerialization(): void |
89
|
|
|
{ |
90
|
|
|
$instance = new Month(Month::SEPTEMBER); |
91
|
|
|
$serialized = \serialize($instance); |
92
|
|
|
$unserialized = \unserialize($serialized); |
93
|
|
|
|
94
|
|
|
$this->assertEquals($instance, $unserialized); |
95
|
|
|
$this->assertEquals(Month::SEPTEMBER, $instance()); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|