Skip to content

Commit

Permalink
Improve InteractsWithInput::enum test (#53057)
Browse files Browse the repository at this point in the history
  • Loading branch information
toarupg0318 authored Oct 8, 2024
1 parent 3ca438b commit 12f208c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
7 changes: 7 additions & 0 deletions tests/Http/Enums.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ enum TestEnumBacked: string
case test_empty = '';
}

enum TestIntegerEnumBacked: int
{
case minus_1 = -1;
case zero = 0;
case plus_1 = 1;
}

enum TestEnum
{
case test;
Expand Down
23 changes: 22 additions & 1 deletion tests/Http/HttpRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -763,15 +763,36 @@ public function testEnumMethod()
'valid_enum_value' => 'test',
'invalid_enum_value' => 'invalid',
'empty_value_request' => '',
'string' => [
'minus_1' => '-1',
'0' => '0',
'plus_1' => '1',
'doesnt_exist' => '-1024',
],
'int' => [
'minus_1' => -1,
'0' => 0,
'plus_1' => 1,
'doesnt_exist' => 1024,
],
]);

$this->assertNull($request->enum('doesnt_exists', TestEnumBacked::class));
$this->assertNull($request->enum('doesnt_exist', TestEnumBacked::class));

$this->assertEquals(TestEnumBacked::test, $request->enum('valid_enum_value', TestEnumBacked::class));

$this->assertNull($request->enum('invalid_enum_value', TestEnumBacked::class));
$this->assertNull($request->enum('empty_value_request', TestEnumBacked::class));
$this->assertNull($request->enum('valid_enum_value', TestEnum::class));

$this->assertEquals(TestIntegerEnumBacked::minus_1, $request->enum('string.minus_1', TestIntegerEnumBacked::class));
$this->assertEquals(TestIntegerEnumBacked::zero, $request->enum('string.0', TestIntegerEnumBacked::class));
$this->assertEquals(TestIntegerEnumBacked::plus_1, $request->enum('string.plus_1', TestIntegerEnumBacked::class));
$this->assertNull($request->enum('string.doesnt_exist', TestIntegerEnumBacked::class));
$this->assertEquals(TestIntegerEnumBacked::minus_1, $request->enum('int.minus_1', TestIntegerEnumBacked::class));
$this->assertEquals(TestIntegerEnumBacked::zero, $request->enum('int.0', TestIntegerEnumBacked::class));
$this->assertEquals(TestIntegerEnumBacked::plus_1, $request->enum('int.plus_1', TestIntegerEnumBacked::class));
$this->assertNull($request->enum('int.doesnt_exist', TestIntegerEnumBacked::class));
}

public function testArrayAccess()
Expand Down

0 comments on commit 12f208c

Please sign in to comment.