-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for native enums to make the migration easier
- Loading branch information
Showing
3 changed files
with
84 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Mhujer\ConsistencePhpunit; | ||
|
||
use Mhujer\ConsistencePhpunit\Fixtures\CardColor; | ||
use Mhujer\ConsistencePhpunit\Fixtures\CardColorNative; | ||
|
||
final class EnumAssertNativeEnumTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
|
||
public function testComparingTwoSimilarEnumValuesWork(): void | ||
{ | ||
EnumAssert::assertSame(CardColorNative::RED, CardColorNative::RED); | ||
} | ||
|
||
public function testAssertSameEnumFailsIfActualValueIsNotAnEnum(): void | ||
{ | ||
$this->expectException(\PHPUnit\Framework\ExpectationFailedException::class); | ||
$this->expectExceptionMessage('Failed asserting that \'foobar\' is an instance of interface "BackedEnum".'); | ||
|
||
EnumAssert::assertSame(CardColorNative::RED, 'foobar'); | ||
} | ||
|
||
public function testAssertSameEnumFailsIfExpectedValueIsNotAnEnum(): void | ||
{ | ||
$this->expectException(\PHPUnit\Framework\ExpectationFailedException::class); | ||
$this->expectExceptionMessage('Failed asserting that \'foobar2\' is an instance of interface "BackedEnum".'); | ||
|
||
EnumAssert::assertSame('foobar2', CardColorNative::BLACK); | ||
} | ||
|
||
public function testAssertSameEnumFailsIfTheEnumsAreNotSame(): void | ||
{ | ||
$this->expectException(\PHPUnit\Framework\ExpectationFailedException::class); | ||
$this->expectExceptionMessage('Expected "Mhujer\ConsistencePhpunit\Fixtures\CardColorNative:red", but got "Mhujer\ConsistencePhpunit\Fixtures\CardColorNative:black"'); | ||
|
||
EnumAssert::assertSame(CardColorNative::RED, CardColorNative::BLACK); | ||
} | ||
|
||
|
||
public function testComparingNativeEnumWithConsisteneEnum(): void | ||
{ | ||
$this->expectException(\PHPUnit\Framework\ExpectationFailedException::class); | ||
$this->expectExceptionMessage('Failed asserting that Mhujer\ConsistencePhpunit\Fixtures\CardColorNative Object (...) is an instance of class "Consistence\Enum\Enum".'); | ||
|
||
EnumAssert::assertSame(CardColorNative::RED, CardColor::get(CardColor::BLACK)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Mhujer\ConsistencePhpunit\Fixtures; | ||
|
||
enum CardColorNative: string | ||
{ | ||
|
||
case BLACK = 'black'; | ||
case RED = 'red'; | ||
|
||
} |