Test Failed
Push — master ( 3d62fc...ee679a )
by Laurens
02:42
created

AbstractEnumTest::testException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace Werkspot\Enum\Tests;
3
4
use PHPUnit_Framework_TestCase;
5
6
class AbstractEnumTest extends PHPUnit_Framework_TestCase
7
{
8
    public function testEnum()
9
    {
10
        $a = TestEnum::get(TestEnum::A);
11
        $b = TestEnum::get(TestEnum::B);
12
13
        $this->assertSame(TestEnum::A, $a->getValue());
14
        $this->assertSame(TestEnum::B, $b->getValue());
15
        $this->assertSame(TestEnum::A, (string) $a);
16
        $this->assertSame(TestEnum::B, (string) $b);
17
    }
18
19
    public function testNull()
20
    {
21
        $nullEnum = TestEnum::get(null);
22
        $this->assertNull($nullEnum->getValue());
23
        $this->assertSame('', (string) $nullEnum);
24
    }
25
26
    public function testInteger()
27
    {
28
        $integerEnum = TestEnum::get(3);
29
        $this->assertSame(3, $integerEnum->getValue());
30
        $this->assertSame('3', (string) $integerEnum);
31
    }
32
33
    public function testSingleton()
34
    {
35
        $a = TestEnum::get(TestEnum::A);
36
        $a2 = TestEnum::get(TestEnum::A);
37
        $b = TestEnum::get(TestEnum::B);
38
39
        $this->assertSame($a, $a2);
40
        $this->assertNotSame($a, $b);
41
    }
42
43
    /**
44
     * @expectedException \InvalidArgumentException
45
     * @dataProvider getExceptionData
46
     */
47
    public function testException($illegalValue)
48
    {
49
        TestEnum::get($illegalValue);
50
    }
51
52
    public function getExceptionData()
53
    {
54
        return array(
55
            array('a'),
56
            array('bee'),
57
            array('B '),
58
            array('C'),
59
            array(true),
60
        );
61
    }
62
63
    public function testGetValidOptions()
64
    {
65
        $this->assertSame(
66
            array(
67
                TestEnum::A,
68
                TestEnum::B,
69
                TestEnum::A3,
70
                TestEnum::ANULL,
71
            ),
72
            TestEnum::getValidOptions()
73
        );
74
    }
75
76
}
77