|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Yokai\Enum\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use Yokai\Enum\EnumRegistry; |
|
6
|
|
|
use Yokai\Enum\Tests\Fixtures\GenderEnum; |
|
7
|
|
|
use Yokai\Enum\Tests\Fixtures\StateEnum; |
|
8
|
|
|
use Yokai\Enum\Tests\Fixtures\SubscriptionEnum; |
|
9
|
|
|
use Yokai\Enum\Tests\Fixtures\TypeEnum; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @author Yann Eugoné <[email protected]> |
|
13
|
|
|
*/ |
|
14
|
|
|
class EnumRegistryTest extends \PHPUnit_Framework_TestCase |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var EnumRegistry |
|
18
|
|
|
*/ |
|
19
|
|
|
private $registry; |
|
20
|
|
|
|
|
21
|
|
|
protected function setUp() |
|
22
|
|
|
{ |
|
23
|
|
|
$this->registry = new EnumRegistry; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
protected function tearDown() |
|
27
|
|
|
{ |
|
28
|
|
|
unset($this->registry); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function testAddDuplicatedException() |
|
32
|
|
|
{ |
|
33
|
|
|
$this->expectException('Yokai\Enum\Exception\DuplicatedEnumException'); |
|
34
|
|
|
$this->registry->add(new GenderEnum); |
|
35
|
|
|
$this->registry->add(new GenderEnum); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testGetInvalidException() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->expectException('Yokai\Enum\Exception\InvalidEnumException'); |
|
41
|
|
|
$this->registry->add(new GenderEnum); |
|
42
|
|
|
$this->registry->get('type'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function testAddNominal() |
|
46
|
|
|
{ |
|
47
|
|
|
$translator = $this->prophesize('Symfony\Component\Translation\TranslatorInterface')->reveal(); |
|
48
|
|
|
$gender = new GenderEnum; |
|
49
|
|
|
$state = new StateEnum($translator); |
|
50
|
|
|
$subscription = new SubscriptionEnum($translator); |
|
51
|
|
|
$type = new TypeEnum; |
|
52
|
|
|
|
|
53
|
|
|
$this->registry->add($gender); |
|
54
|
|
|
$this->registry->add($state); |
|
55
|
|
|
$this->registry->add($subscription); |
|
56
|
|
|
$this->registry->add($type); |
|
57
|
|
|
|
|
58
|
|
|
$this->assertTrue($this->registry->has(GenderEnum::class)); |
|
59
|
|
|
$this->assertTrue($this->registry->has('state')); |
|
60
|
|
|
$this->assertTrue($this->registry->has('subscription')); |
|
61
|
|
|
$this->assertTrue($this->registry->has('type')); |
|
62
|
|
|
|
|
63
|
|
|
$this->assertSame($gender, $this->registry->get(GenderEnum::class)); |
|
64
|
|
|
$this->assertSame($state, $this->registry->get('state')); |
|
65
|
|
|
$this->assertSame($subscription, $this->registry->get('subscription')); |
|
66
|
|
|
$this->assertSame($type, $this->registry->get('type')); |
|
67
|
|
|
$this->assertSame( |
|
68
|
|
|
[GenderEnum::class => $gender, 'state' => $state, 'subscription' => $subscription, 'type' => $type], |
|
69
|
|
|
$this->registry->all() |
|
70
|
|
|
); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|