Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
tomschlick committed Jan 29, 2023
2 parents e30fc2b + 22c169f commit 91a0867
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 27 deletions.
1 change: 0 additions & 1 deletion tests/IntEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ enum IntEnum: int
case TWO = 2;
case THREE = 3;
}

42 changes: 18 additions & 24 deletions tests/LaravelEnumsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,37 @@

declare(strict_types=1);


use ReturnEarly\LaravelEnums\Tests\IntEnum;
use ReturnEarly\LaravelEnums\Tests\StringEnum;

test('int enums can be called statically for a value', function() {
test('int enums can be called statically for a value', function () {
$this->assertEquals(1, IntEnum::ONE());
});


test('string enums can be called statically for a value', function() {
test('string enums can be called statically for a value', function () {
$this->assertEquals('A', StringEnum::A());
});


test('an enum can be checked with is', function() {
test('an enum can be checked with is', function () {
$this->assertTrue(IntEnum::ONE->is(IntEnum::ONE));
$this->assertFalse(IntEnum::ONE->is(IntEnum::TWO));
});


test('an enum can be checked with is not', function() {
test('an enum can be checked with is not', function () {
$this->assertTrue(IntEnum::ONE->isNot(IntEnum::TWO));
$this->assertFalse(IntEnum::ONE->isNot(IntEnum::ONE));
});


test('an int enum can check if its value is between others', function() {
test('an int enum can check if its value is between others', function () {
$this->assertTrue(IntEnum::TWO->isBetween(IntEnum::ONE, IntEnum::THREE));
$this->assertFalse(IntEnum::ONE->isBetween(IntEnum::TWO, IntEnum::THREE));
});


test('an int enum can check if the collection contains its value', function() {
test('an int enum can check if the collection contains its value', function () {
$this->assertTrue(IntEnum::contains('2'));
});

test('an enum can manifest as a collection', function() {
test('an enum can manifest as a collection', function () {
$this->assertEquals(
[
IntEnum::ONE,
Expand All @@ -49,7 +43,7 @@
);
});

test('an enum can get its values as a collection', function() {
test('an enum can get its values as a collection', function () {
$this->assertEquals(
[
1,
Expand All @@ -60,7 +54,7 @@
);
});

test('an enum can get its names as a collection', function() {
test('an enum can get its names as a collection', function () {
$this->assertEquals(
[
'ONE',
Expand All @@ -71,7 +65,7 @@
);
});

test('an enum can get its values as a select array', function() {
test('an enum can get its values as a select array', function () {
$this->assertEquals(
[
1 => 'ONE',
Expand All @@ -82,38 +76,38 @@
);
});

test('an enum can get its values between two others excluding those others', function() {
test('an enum can get its values between two others excluding those others', function () {
expect(IntEnum::valuesBetween(IntEnum::ONE, IntEnum::THREE, false)->toArray())
->toHaveCount(1);
});

test('an enum can get its values between two others including those others', function() {
test('an enum can get its values between two others including those others', function () {
expect(IntEnum::valuesBetween(IntEnum::ONE, IntEnum::THREE, true)->toArray())
->toHaveCount(3);
});

test('an enum can check if it is any of a list of enums', function() {
test('an enum can check if it is any of a list of enums', function () {
$this->assertTrue(IntEnum::ONE->isAny([IntEnum::ONE, IntEnum::TWO]));
$this->assertFalse(IntEnum::ONE->isAny([IntEnum::TWO, IntEnum::THREE]));
});

test('an enum can be created from a value', function() {
test('an enum can be created from a value', function () {
$this->assertEquals(IntEnum::ONE, IntEnum::fromValue(1));
});

test('an enum can be created from another enum', function() {
test('an enum can be created from another enum', function () {
$this->assertEquals(IntEnum::ONE, IntEnum::fromValue(IntEnum::ONE));
});

test('an enum can get its name', function() {
test('an enum can get its name', function () {
$this->assertEquals('ONE', IntEnum::ONE->name());
});

test('an enum can get its value', function() {
test('an enum can get its value', function () {
$this->assertEquals(1, IntEnum::ONE->value());
});

test('a missing method throws a bad method call exception', function() {
test('a missing method throws a bad method call exception', function () {
$this->expectException(BadMethodCallException::class);
IntEnum::FOUR();
});
1 change: 0 additions & 1 deletion tests/StringEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ enum StringEnum: string
case B = 'B';
case C = 'C';
}

1 change: 0 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@ protected function getPackageProviders($app): array

public function getEnvironmentSetUp($app)
{

}
}

0 comments on commit 91a0867

Please sign in to comment.