-
Notifications
You must be signed in to change notification settings - Fork 186
Expand file tree
/
Copy pathAssertEnumTest.php
More file actions
68 lines (58 loc) · 1.99 KB
/
AssertEnumTest.php
File metadata and controls
68 lines (58 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/**
* Assert
*
* LICENSE
*
* This source file is subject to the MIT license that is bundled
* with this package in the file LICENSE.txt.
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to kontakt@beberlei.de so I can send you a copy immediately.
*/
namespace Assert\Tests;
use Assert\Assertion;
use Assert\Tests\Fixtures\TestBackedEnum;
use Assert\Tests\Fixtures\TestUnitEnum;
use Yoast\PHPUnitPolyfills\TestCases\TestCase;
class AssertEnumTest extends TestCase
{
public static function setUpBeforeClass(): void
{
if (\PHP_VERSION_ID < 80100) {
static::markTestSkipped('Enum is not supported in this PHP version.');
}
}
public function testValidEnumExists()
{
$this->assertTrue(Assertion::enumExists(TestUnitEnum::class));
}
public function testInvalidEnumExists()
{
$this->expectException('Assert\AssertionFailedException');
$this->expectExceptionCode(\Assert\Assertion::INVALID_ENUM);
Assertion::enumExists('InvalidEnum');
}
public function testValidEnumCase()
{
$this->assertTrue(Assertion::enumCase('one', TestBackedEnum::class));
}
public function testEnumCaseInvalidValue()
{
$this->expectException('Assert\AssertionFailedException');
$this->expectExceptionCode(\Assert\Assertion::INVALID_ENUM_CASE);
Assertion::enumCase('three', TestBackedEnum::class);
}
public function testEnumCaseInvalidEnum()
{
$this->expectException('Assert\AssertionFailedException');
$this->expectExceptionCode(\Assert\Assertion::INVALID_ENUM);
Assertion::enumCase('three', 'InvalidEnum');
}
public function testEnumCaseNonBackedEnum()
{
$this->expectException('Assert\AssertionFailedException');
$this->expectExceptionCode(\Assert\Assertion::INTERFACE_NOT_IMPLEMENTED);
Assertion::enumCase('first', TestUnitEnum::class);
}
}