From d470014c8e862aedd22bd25bd479beda94de42cd Mon Sep 17 00:00:00 2001 From: toarupi0318 Date: Tue, 8 Oct 2024 15:28:13 +0900 Subject: [PATCH] Improve InteractsWithInput::enum test --- tests/Http/Enums.php | 7 +++++++ tests/Http/HttpRequestTest.php | 23 ++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/tests/Http/Enums.php b/tests/Http/Enums.php index f3d74e8afdd3..0353cd1f27b3 100644 --- a/tests/Http/Enums.php +++ b/tests/Http/Enums.php @@ -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; diff --git a/tests/Http/HttpRequestTest.php b/tests/Http/HttpRequestTest.php index 7c4f26872d5c..7141822666d6 100644 --- a/tests/Http/HttpRequestTest.php +++ b/tests/Http/HttpRequestTest.php @@ -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()