From fd66d9475371c518612181cc99bebec2bc1e17ee Mon Sep 17 00:00:00 2001 From: Peter Fox Date: Thu, 11 May 2023 16:15:35 +0100 Subject: [PATCH 1/2] Gone, InternalServerError & ServiceUnavailable in AssertStatusRule --- .../AssertStatusToAssertMethodRector.php | 6 ++++ .../AssertStatusToAssertMethodTest.php | 2 +- ...with_illuminate_response_constants.php.inc | 30 +++++++++++++++++++ .../fixture_with_magic_numbers.php.inc | 30 +++++++++++++++++++ 4 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/Rector/MethodCall/AssertStatusToAssertMethodRector.php b/src/Rector/MethodCall/AssertStatusToAssertMethodRector.php index e7d58a65..8b5aab27 100644 --- a/src/Rector/MethodCall/AssertStatusToAssertMethodRector.php +++ b/src/Rector/MethodCall/AssertStatusToAssertMethodRector.php @@ -165,7 +165,10 @@ private function updateAssertStatusCall(MethodCall $methodCall): ?MethodCall 401 => 'assertUnauthorized', 403 => 'assertForbidden', 404 => 'assertNotFound', + 410 => 'assertGone', 422 => 'assertUnprocessable', + 500 => 'assertInternalServerError', + 503 => 'assertServiceUnavailable', default => null }; } else { @@ -182,7 +185,10 @@ private function updateAssertStatusCall(MethodCall $methodCall): ?MethodCall 'HTTP_UNAUTHORIZED' => 'assertUnauthorized', 'HTTP_FORBIDDEN' => 'assertForbidden', 'HTTP_NOT_FOUND' => 'assertNotFound', + 'HTTP_GONE' => 'assertGone', 'HTTP_UNPROCESSABLE_ENTITY' => 'assertUnprocessable', + 'HTTP_INTERNAL_SERVER_ERROR' => 'assertInternalServerError', + 'HTTP_SERVICE_UNAVAILABLE' => 'assertServiceUnavailable', default => null }; } diff --git a/tests/Rector/MethodCall/AssertStatusToAssertMethodRector/AssertStatusToAssertMethodTest.php b/tests/Rector/MethodCall/AssertStatusToAssertMethodRector/AssertStatusToAssertMethodTest.php index 07dbf8c8..821bd94b 100644 --- a/tests/Rector/MethodCall/AssertStatusToAssertMethodRector/AssertStatusToAssertMethodTest.php +++ b/tests/Rector/MethodCall/AssertStatusToAssertMethodRector/AssertStatusToAssertMethodTest.php @@ -17,7 +17,7 @@ public function test(string $filePath): void $this->doTestFile($filePath); } - public function provideData(): Iterator + public static function provideData(): Iterator { return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); } diff --git a/tests/Rector/MethodCall/AssertStatusToAssertMethodRector/Fixture/fixture_with_illuminate_response_constants.php.inc b/tests/Rector/MethodCall/AssertStatusToAssertMethodRector/Fixture/fixture_with_illuminate_response_constants.php.inc index b26793dd..5311b341 100644 --- a/tests/Rector/MethodCall/AssertStatusToAssertMethodRector/Fixture/fixture_with_illuminate_response_constants.php.inc +++ b/tests/Rector/MethodCall/AssertStatusToAssertMethodRector/Fixture/fixture_with_illuminate_response_constants.php.inc @@ -33,6 +33,21 @@ class FixtureWithIlluminateTest { $response->assertStatus(\Symfony\Component\HttpFoundation\Response::HTTP_UNPROCESSABLE_ENTITY); } + + public function testGone(\Illuminate\Testing\TestResponse $response) + { + $response->assertStatus(\Symfony\Component\HttpFoundation\Response::HTTP_GONE); + } + + public function testInternalServerError(\Illuminate\Testing\TestResponse $response) + { + $response->assertStatus(\Symfony\Component\HttpFoundation\Response::HTTP_INTERNAL_SERVER_ERROR); + } + + public function testServiceUnavailable(\Illuminate\Testing\TestResponse $response) + { + $response->assertStatus(\Symfony\Component\HttpFoundation\Response::HTTP_SERVICE_UNAVAILABLE); + } } ?> @@ -72,6 +87,21 @@ class FixtureWithIlluminateTest { $response->assertUnprocessable(); } + + public function testGone(\Illuminate\Testing\TestResponse $response) + { + $response->assertGone(); + } + + public function testInternalServerError(\Illuminate\Testing\TestResponse $response) + { + $response->assertInternalServerError(); + } + + public function testServiceUnavailable(\Illuminate\Testing\TestResponse $response) + { + $response->assertServiceUnavailable(); + } } ?> diff --git a/tests/Rector/MethodCall/AssertStatusToAssertMethodRector/Fixture/fixture_with_magic_numbers.php.inc b/tests/Rector/MethodCall/AssertStatusToAssertMethodRector/Fixture/fixture_with_magic_numbers.php.inc index 70fb9d33..1c08c9cc 100644 --- a/tests/Rector/MethodCall/AssertStatusToAssertMethodRector/Fixture/fixture_with_magic_numbers.php.inc +++ b/tests/Rector/MethodCall/AssertStatusToAssertMethodRector/Fixture/fixture_with_magic_numbers.php.inc @@ -33,6 +33,21 @@ class FixtureTest { $response->assertStatus(422); } + + public function testGone(\Illuminate\Testing\TestResponse $response) + { + $response->assertStatus(410); + } + + public function testInternalServerError(\Illuminate\Testing\TestResponse $response) + { + $response->assertStatus(500); + } + + public function testServiceUnavailable(\Illuminate\Testing\TestResponse $response) + { + $response->assertStatus(503); + } } ?> @@ -72,6 +87,21 @@ class FixtureTest { $response->assertUnprocessable(); } + + public function testGone(\Illuminate\Testing\TestResponse $response) + { + $response->assertGone(); + } + + public function testInternalServerError(\Illuminate\Testing\TestResponse $response) + { + $response->assertInternalServerError(); + } + + public function testServiceUnavailable(\Illuminate\Testing\TestResponse $response) + { + $response->assertServiceUnavailable(); + } } ?> From 9a8b77de7cd3440ab3edc365445dfbfc0340a5fb Mon Sep 17 00:00:00 2001 From: Peter Fox Date: Thu, 11 May 2023 16:21:58 +0100 Subject: [PATCH 2/2] Update code samples --- .../AssertStatusToAssertMethodRector.php | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/Rector/MethodCall/AssertStatusToAssertMethodRector.php b/src/Rector/MethodCall/AssertStatusToAssertMethodRector.php index 8b5aab27..a97b4f2e 100644 --- a/src/Rector/MethodCall/AssertStatusToAssertMethodRector.php +++ b/src/Rector/MethodCall/AssertStatusToAssertMethodRector.php @@ -67,6 +67,27 @@ public function testUnprocessableEntity() $this->get('/')->assertStatus(\Illuminate\Http\Response::HTTP_UNPROCESSABLE_ENTITY); $this->get('/')->assertStatus(\Symfony\Component\HttpFoundation\Response::HTTP_UNPROCESSABLE_ENTITY); } + + public function testGone() + { + $this->get('/')->assertStatus(410); + $this->get('/')->assertStatus(\Illuminate\Http\Response::HTTP_GONE); + $this->get('/')->assertStatus(\Symfony\Component\HttpFoundation\Response::HTTP_GONE); + } + + public function testInternalServerError() + { + $this->get('/')->assertStatus(500); + $this->get('/')->assertStatus(\Illuminate\Http\Response::HTTP_INTERNAL_SERVER_ERROR); + $this->get('/')->assertStatus(\Symfony\Component\HttpFoundation\Response::HTTP_INTERNAL_SERVER_ERROR); + } + + public function testServiceUnavailable() + { + $this->get('/')->assertStatus(503); + $this->get('/')->assertStatus(\Illuminate\Http\Response::HTTP_SERVICE_UNAVAILABLE); + $this->get('/')->assertStatus(\Symfony\Component\HttpFoundation\Response::HTTP_SERVICE_UNAVAILABLE); + } } CODE_SAMPLE , @@ -114,6 +135,27 @@ public function testUnprocessableEntity() $this->get('/')->assertUnprocessable(); $this->get('/')->assertUnprocessable(); } + + public function testGone() + { + $this->get('/')->assertGone(); + $this->get('/')->assertGone(); + $this->get('/')->assertGone(); + } + + public function testInternalServerError() + { + $this->get('/')->assertInternalServerError(); + $this->get('/')->assertInternalServerError(); + $this->get('/')->assertInternalServerError(); + } + + public function testServiceUnavailable() + { + $this->get('/')->asserServiceUnavailable(); + $this->get('/')->asserServiceUnavailable(); + $this->get('/')->asserServiceUnavailable(); + } } CODE_SAMPLE ),