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

AbstractEnumTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 71
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testEnum() 0 10 1
A testNull() 0 6 1
A testInteger() 0 6 1
A testSingleton() 0 9 1
A testException() 0 4 1
A getExceptionData() 0 10 1
A testGetValidOptions() 0 12 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