Skip to content

Commit c311714

Browse files
committed
Add more tests
1 parent ad7abab commit c311714

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

tests/ConstructorFixture.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
/**
3+
* @link http://github.com/myclabs/php-enum
4+
* @license http://www.opensource.org/licenses/mit-license.php MIT (see the LICENSE file)
5+
*/
6+
7+
namespace MyCLabs\Tests\Enum;
8+
9+
use MyCLabs\Enum\Enum;
10+
11+
/**
12+
* Class ConstructorFixture
13+
*
14+
* @method static ConstructorFixture ONCE()
15+
*/
16+
class ConstructorFixture extends Enum
17+
{
18+
public function __construct()
19+
{
20+
/* noop */
21+
}
22+
23+
const TEST = 'OK';
24+
}

tests/EnumTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,39 @@ public function testEqualsComparesProblematicValuesProperly()
230230
$this->assertFalse($null->equals($false));
231231
}
232232

233+
/**
234+
* fromKey()
235+
*/
236+
public function testFromKey()
237+
{
238+
$number = EnumFixture::BAR();
239+
$fromValue = EnumFixture::fromKey('BAR');
240+
241+
$this->assertSame($number, $fromValue);
242+
}
243+
244+
/**
245+
* fromValue()
246+
*/
247+
public function testFromValue()
248+
{
249+
$enum = EnumFixture::NUMBER();
250+
$number = EnumFixture::fromValue(42);
251+
$inexistant = EnumFixture::fromValue('inexistant');
252+
253+
$this->assertSame($enum, $number);
254+
$this->assertSame(null, $inexistant);
255+
}
256+
257+
/**
258+
* @expectedException \BadMethodCallException
259+
*/
260+
public function testConstructor()
261+
{
262+
$number = ConstructorFixture::TEST();
263+
$number->getValue();
264+
}
265+
233266
/**
234267
* __wakeup()
235268
*/

0 commit comments

Comments
 (0)