Completed
Pull Request — master (#29)
by Yann
10:30
created

EnumRegistryTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 7
dl 0
loc 59
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A tearDown() 0 4 1
A testAddDuplicatedException() 0 6 1
A testGetInvalidException() 0 6 1
B testAddNominal() 0 27 1
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