|
20 | 20 |
|
21 | 21 | class MabeTest_EnumTest extends PHPUnit_Framework_TestCase
|
22 | 22 | {
|
23 |
| - |
24 |
| - public function testEnumWithDefaultValue() |
25 |
| - { |
26 |
| - $enum = new EnumWithDefaultValue(); |
27 |
| - |
28 |
| - $this->assertSame(array( |
29 |
| - 'ONE' => 1, |
30 |
| - 'TWO' => 2, |
31 |
| - ), $enum->getConstants()); |
32 |
| - |
33 |
| - $this->assertSame(1, $enum->getValue()); |
34 |
| - $this->assertSame(1, $enum->__invoke()); |
35 |
| - |
36 |
| - $this->assertSame('ONE', $enum->getName()); |
37 |
| - $this->assertSame('ONE', $enum->__toString()); |
38 |
| - } |
39 |
| - |
40 |
| - public function testEnumWithNullAsDefaultValue() |
41 |
| - { |
42 |
| - $enum = new EnumWithNullAsDefaultValue(); |
43 |
| - |
44 |
| - $this->assertSame(array( |
45 |
| - 'NONE' => null, |
46 |
| - 'ONE' => 1, |
47 |
| - 'TWO' => 2, |
48 |
| - ), $enum->getConstants()); |
49 |
| - |
50 |
| - $this->assertNull($enum->getValue()); |
51 |
| - $this->assertNull($enum->__invoke()); |
52 |
| - |
53 |
| - $this->assertSame('NONE', $enum->getName()); |
54 |
| - $this->assertSame('NONE', $enum->__toString()); |
55 |
| - } |
56 |
| - |
57 |
| - public function testEnumWithoutDefaultValue() |
58 |
| - { |
59 |
| - $this->setExpectedException('InvalidArgumentException'); |
60 |
| - new EnumWithoutDefaultValue(); |
61 |
| - } |
62 |
| - |
63 |
| - public function testEnumInheritance() |
64 |
| - { |
65 |
| - $enum = new EnumInheritance(EnumInheritance::ONE); |
66 |
| - $this->assertSame(EnumInheritance::ONE, $enum->getValue()); |
67 |
| - |
68 |
| - $enum = new EnumInheritance(EnumInheritance::INHERITACE); |
69 |
| - $this->assertSame(EnumInheritance::INHERITACE, $enum->getValue()); |
70 |
| - } |
71 |
| - |
72 |
| - public function testChangeValueOnConstructor() |
73 |
| - { |
74 |
| - $enum = new EnumWithoutDefaultValue(1); |
75 |
| - |
76 |
| - $this->assertSame(1, $enum->getValue()); |
77 |
| - $this->assertSame(1, $enum->__invoke()); |
78 |
| - |
79 |
| - $this->assertSame('ONE', $enum->getName()); |
80 |
| - $this->assertSame('ONE', $enum->__toString()); |
81 |
| - } |
82 |
| - |
83 |
| - public function testChangeValueOnConstructorThrowsInvalidArgumentExceptionOnStrictComparison() |
84 |
| - { |
85 |
| - $this->setExpectedException('InvalidArgumentException'); |
86 |
| - $enum = new EnumWithoutDefaultValue('1'); |
87 |
| - } |
88 |
| - |
89 |
| - public function testSetValue() |
90 |
| - { |
91 |
| - $enum = new EnumWithDefaultValue(); |
92 |
| - $enum->setValue(2); |
93 |
| - |
94 |
| - $this->assertSame(2, $enum->getValue()); |
95 |
| - $this->assertSame(2, $enum->__invoke()); |
96 |
| - |
97 |
| - $this->assertSame('TWO', $enum->getName()); |
98 |
| - $this->assertSame('TWO', $enum->__toString()); |
99 |
| - } |
100 |
| - |
101 |
| - public function testSetValueThrowsInvalidArgumentExceptionOnStrictComparison() |
102 |
| - { |
103 |
| - $this->setExpectedException('InvalidArgumentException'); |
104 |
| - $enum = new EnumWithDefaultValue(); |
105 |
| - $enum->setValue('2'); |
106 |
| - } |
107 |
| - |
| 23 | + |
| 24 | + public function testEnumWithDefaultValue() |
| 25 | + { |
| 26 | + $enum = new EnumWithDefaultValue(); |
| 27 | + |
| 28 | + $this->assertSame(array( |
| 29 | + 'ONE' => 1, |
| 30 | + 'TWO' => 2, |
| 31 | + ), $enum->getConstants()); |
| 32 | + |
| 33 | + $this->assertSame(1, $enum->getValue()); |
| 34 | + $this->assertSame('1', $enum->__toString()); |
| 35 | + |
| 36 | + $this->assertSame('ONE', $enum->getName()); |
| 37 | + } |
| 38 | + |
| 39 | + public function testGetNameReturnsConstantNameOfCurrentValue() |
| 40 | + { |
| 41 | + $enum = new EnumWithoutDefaultValue(EnumWithoutDefaultValue::ONE); |
| 42 | + $this->assertSame('ONE', $enum->getName()); |
| 43 | + } |
| 44 | + |
| 45 | + public function testToStringMagicMethodReturnsValueAsString() |
| 46 | + { |
| 47 | + $enum = new EnumWithoutDefaultValue(EnumWithoutDefaultValue::ONE); |
| 48 | + $this->assertSame('1', $enum->__toString()); |
| 49 | + } |
| 50 | + |
| 51 | + public function testEnumWithNullAsDefaultValue() |
| 52 | + { |
| 53 | + $enum = new EnumWithNullAsDefaultValue(); |
| 54 | + |
| 55 | + $this->assertSame(array( |
| 56 | + 'NONE' => null, |
| 57 | + 'ONE' => 1, |
| 58 | + 'TWO' => 2, |
| 59 | + ), $enum->getConstants()); |
| 60 | + |
| 61 | + $this->assertNull($enum->getValue()); |
| 62 | + } |
| 63 | + |
| 64 | + public function testEnumWithoutDefaultValue() |
| 65 | + { |
| 66 | + $this->setExpectedException('InvalidArgumentException'); |
| 67 | + new EnumWithoutDefaultValue(); |
| 68 | + } |
| 69 | + |
| 70 | + public function testEnumInheritance() |
| 71 | + { |
| 72 | + $enum = new EnumInheritance(EnumInheritance::ONE); |
| 73 | + $this->assertSame(EnumInheritance::ONE, $enum->getValue()); |
| 74 | + |
| 75 | + $enum = new EnumInheritance(EnumInheritance::INHERITACE); |
| 76 | + $this->assertSame(EnumInheritance::INHERITACE, $enum->getValue()); |
| 77 | + } |
| 78 | + |
| 79 | + public function testChangeValueOnConstructor() |
| 80 | + { |
| 81 | + $enum = new EnumWithoutDefaultValue(1); |
| 82 | + $this->assertSame(1, $enum->getValue()); |
| 83 | + } |
| 84 | + |
| 85 | + public function testChangeValueOnConstructorThrowsInvalidArgumentExceptionOnStrictComparison() |
| 86 | + { |
| 87 | + $this->setExpectedException('InvalidArgumentException'); |
| 88 | + $enum = new EnumWithoutDefaultValue('1'); |
| 89 | + } |
| 90 | + |
| 91 | + public function testSetValue() |
| 92 | + { |
| 93 | + $enum = new EnumWithDefaultValue(); |
| 94 | + $enum->setValue(2); |
| 95 | + |
| 96 | + $this->assertSame(2, $enum->getValue()); |
| 97 | + } |
| 98 | + |
| 99 | + public function testSetValueThrowsInvalidArgumentExceptionOnStrictComparison() |
| 100 | + { |
| 101 | + $this->setExpectedException('InvalidArgumentException'); |
| 102 | + $enum = new EnumWithDefaultValue(); |
| 103 | + $enum->setValue('2'); |
| 104 | + } |
108 | 105 | }
|
109 | 106 |
|
110 | 107 | class EnumWithDefaultValue extends Mabe_Enum
|
111 | 108 | {
|
112 |
| - const ONE = 1; |
113 |
| - const TWO = 2; |
114 |
| - protected $value = 1; |
| 109 | + const ONE = 1; |
| 110 | + const TWO = 2; |
| 111 | + protected $value = 1; |
115 | 112 | }
|
116 | 113 |
|
117 | 114 | class EnumWithNullAsDefaultValue extends Mabe_Enum
|
118 | 115 | {
|
119 |
| - const NONE = null; |
120 |
| - const ONE = 1; |
121 |
| - const TWO = 2; |
| 116 | + const NONE = null; |
| 117 | + const ONE = 1; |
| 118 | + const TWO = 2; |
122 | 119 | }
|
123 | 120 |
|
124 | 121 |
|
125 | 122 | class EnumWithoutDefaultValue extends Mabe_Enum
|
126 | 123 | {
|
127 |
| - const ONE = 1; |
128 |
| - const TWO = 2; |
| 124 | + const ONE = 1; |
| 125 | + const TWO = 2; |
129 | 126 | }
|
130 | 127 |
|
131 | 128 | class EnumInheritance extends EnumWithoutDefaultValue
|
132 | 129 | {
|
133 |
| - const INHERITACE = 'Inheritance'; |
| 130 | + const INHERITACE = 'Inheritance'; |
134 | 131 | }
|
135 | 132 |
|
136 | 133 | class EmptyEnum extends Mabe_Enum
|
|
0 commit comments