Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Add tests for handling non-baked enum and empty string requests #51289

Merged
merged 2 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion tests/Http/Enums.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

namespace Illuminate\Tests\Http;

enum TestEnum: string
enum TestEnumBacked: string
{
case test = 'test';
case test_empty = '';
}

enum TestEnum
{
case test;
}
9 changes: 6 additions & 3 deletions tests/Http/HttpRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -762,13 +762,16 @@ public function testEnumMethod()
$request = Request::create('/', 'GET', [
'valid_enum_value' => 'test',
'invalid_enum_value' => 'invalid',
'empty_value_request' => '',
]);

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

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

$this->assertNull($request->enum('invalid_enum_value', TestEnum::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));
}

public function testArrayAccess()
Expand Down