1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* @copyright (c) 2020 Mendel <[email protected]> |
4
|
|
|
* @license see license.txt |
5
|
|
|
*/ |
6
|
|
|
namespace drycart\data\tests; |
7
|
|
|
use drycart\data\tests\dummy\DummyEnum; |
8
|
|
|
use drycart\data\tests\dummy\DummyExtendedEnum; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @author mendel |
12
|
|
|
*/ |
13
|
|
|
class EnumTest extends \PHPUnit\Framework\TestCase |
14
|
|
|
{ |
15
|
|
|
public function testData() |
16
|
|
|
{ |
17
|
|
|
$this->assertEquals(DummyEnum::data(),['GUEST'=>0, 'USER'=>1, 'ADMIN'=>10]); |
18
|
|
|
$this->assertEquals(DummyExtendedEnum::data(),['GUEST'=>0, 'USER'=>1, 'ADMIN'=>10, 'SUPER_ADMIN'=>100]); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function testKeyValue() |
22
|
|
|
{ |
23
|
|
|
$this->assertEquals(DummyEnum::value('ADMIN'),10); |
24
|
|
|
$this->assertEquals(DummyEnum::key(10),'ADMIN'); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testKeyTitles() |
28
|
|
|
{ |
29
|
|
|
$this->assertEquals(DummyEnum::keyTitles(),['GUEST'=>'Guest', 'USER'=>'User', 'ADMIN'=>'Admin']); |
30
|
|
|
$this->assertEquals(DummyExtendedEnum::keyTitles(),['GUEST'=>'Guest', 'USER'=>'Default user', 'ADMIN'=>'Admin', 'SUPER_ADMIN'=>'Super admin']); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testValueTitles() |
34
|
|
|
{ |
35
|
|
|
$this->assertEquals(DummyEnum::valueTitles(),[0=>'Guest', 1=>'User', 10=>'Admin']); |
36
|
|
|
$this->assertEquals(DummyExtendedEnum::valueTitles(),[0=>'Guest', 1=>'Default user', 10=>'Admin', 100=>'Super admin']); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testTitlesIterator() |
40
|
|
|
{ |
41
|
|
|
$arr = iterator_to_array(DummyEnum::titlesIterator()); |
42
|
|
|
$this->assertCount(3, $arr); |
43
|
|
|
$this->assertEquals('GUEST', $arr[0]->key); |
44
|
|
|
$this->assertEquals(0, $arr[0]->value); |
45
|
|
|
$this->assertEquals('Guest', $arr[0]->title); |
46
|
|
|
|
47
|
|
|
$this->assertEquals('USER', $arr[1]->key); |
48
|
|
|
$this->assertEquals(1, $arr[1]->value); |
49
|
|
|
$this->assertEquals('User', $arr[1]->title); |
50
|
|
|
|
51
|
|
|
$this->assertEquals('ADMIN', $arr[2]->key); |
52
|
|
|
$this->assertEquals(10, $arr[2]->value); |
53
|
|
|
$this->assertEquals('Admin', $arr[2]->title); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|