Skip to content

Commit ba8cd72

Browse files
Neutron-ProNeutron-Pro
authored andcommitted
Add test for the priority of values between the values and the indexes
1 parent e7d3f3a commit ba8cd72

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace NeutronStars\Enum\Test\Fixture;
6+
7+
use NeutronStars\Enum\Enum;
8+
9+
/**
10+
* @method static self FOO()
11+
* @method static self BAR()
12+
* Class FooWithValueIntEnum
13+
* @package NeutronStars\Enum\Test\Fixture
14+
*/
15+
class FooWithValueIntEnum extends Enum
16+
{
17+
public const FOO = 2;
18+
public const BAR = 1;
19+
}

test/TestEnum.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use NeutronStars\Enum\Error\ValueError;
88
use NeutronStars\Enum\Test\Fixture\FooWithoutValueEnum;
9+
use NeutronStars\Enum\Test\Fixture\FooWithValueIntEnum;
910
use NeutronStars\Enum\Test\Fixture\FooWithValueStringEnum;
1011
use PHPUnit\Framework\TestCase;
1112

@@ -104,6 +105,20 @@ public function testTryFromEnum(): void
104105
);
105106
}
106107

108+
public function testTryFromPriorityEnum(): void
109+
{
110+
$this->assertSame(
111+
FooWithValueIntEnum::BAR(),
112+
FooWithValueIntEnum::tryFrom(1),
113+
'The value priority did not work.'
114+
);
115+
$this->assertSame(
116+
FooWithValueIntEnum::FOO(),
117+
FooWithValueIntEnum::tryFrom(2),
118+
'The value priority did not work.'
119+
);
120+
}
121+
107122
public function testTryFromEnumWithError(): void
108123
{
109124
$this->assertNull(

0 commit comments

Comments
 (0)