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
|
|
|
unset($instance); |
31
|
|
|
|
32
|
|
|
$instance = new Month(Month::SEPTEMBER); |
33
|
|
|
$this->assertEquals(Month::SEPTEMBER, $instance()); |
34
|
|
|
unset($instance); |
35
|
|
|
|
36
|
|
|
$instance = new Month('1', false); |
37
|
|
|
$this->assertEquals(Month::JANUARY, $instance()); |
38
|
|
|
unset($instance); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Unit test. |
43
|
|
|
* |
44
|
|
|
* @throws \UnexpectedValueException |
45
|
|
|
* |
46
|
|
|
* @return void |
47
|
|
|
*/ |
48
|
|
|
public function testUnexpectedValueRxception(): void |
49
|
|
|
{ |
50
|
|
|
$this->expectException(\UnexpectedValueException::class); |
51
|
|
|
new Month('1'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Unit test. |
56
|
|
|
* |
57
|
|
|
* @return void |
58
|
|
|
*/ |
59
|
|
|
public function testGetConstList(): void |
60
|
|
|
{ |
61
|
|
|
$list = [ |
62
|
|
|
'__default' => 1, |
63
|
|
|
'JANUARY' => 1, |
64
|
|
|
'FEBRUARY' => 2, |
65
|
|
|
'MARCH' => 3, |
66
|
|
|
'APRIL' => 4, |
67
|
|
|
'MAY' => 5, |
68
|
|
|
'JUNE' => 6, |
69
|
|
|
'JULY' => 7, |
70
|
|
|
'AUGUST' => 8, |
71
|
|
|
'SEPTEMBER' => 9, |
72
|
|
|
'OCTOBER' => 10, |
73
|
|
|
'NOVEMBER' => 11, |
74
|
|
|
'DECEMBER' => 12, |
75
|
|
|
]; |
76
|
|
|
$instance = new Month(); |
77
|
|
|
|
78
|
|
|
$test = $instance->getConstList(true); |
79
|
|
|
$this->assertSame($list, $test); |
80
|
|
|
unset($test, $list['__default']); |
81
|
|
|
|
82
|
|
|
$test = $instance->getConstList(); |
83
|
|
|
$this->assertSame($list, $test); |
84
|
|
|
unset($instance, $test, $list); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|