Skip to content

Commit b3fb8f3

Browse files
peterfoxdriftingly
andauthored
MethodNotAllowed assertion added (#112)
Co-authored-by: Anthony Clark <anthonyclark@gmail.com>
1 parent 701a2a6 commit b3fb8f3

File tree

4 files changed

+46
-0
lines changed

4 files changed

+46
-0
lines changed

src/Rector/MethodCall/AssertStatusToAssertMethodRector.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ public function testNotFound()
6464
$this->get('/')->assertStatus(\Symfony\Component\HttpFoundation\Response::HTTP_NOT_FOUND);
6565
}
6666
67+
public function testMethodNotAllowed()
68+
{
69+
$this->get('/')->assertStatus(405);
70+
$this->get('/')->assertStatus(\Illuminate\Http\Response::HTTP_METHOD_NOT_ALLOWED);
71+
$this->get('/')->assertStatus(\Symfony\Component\HttpFoundation\Response::HTTP_METHOD_NOT_ALLOWED);
72+
}
73+
6774
public function testUnprocessableEntity()
6875
{
6976
$this->get('/')->assertStatus(422);
@@ -132,6 +139,13 @@ public function testNotFound()
132139
$this->get('/')->assertNotFound();
133140
}
134141
142+
public function testMethodNotAllowed()
143+
{
144+
$this->get('/')->assertMethodNotAllowed();
145+
$this->get('/')->assertMethodNotAllowed();
146+
$this->get('/')->assertMethodNotAllowed();
147+
}
148+
135149
public function testUnprocessableEntity()
136150
{
137151
$this->get('/')->assertUnprocessable();
@@ -210,6 +224,7 @@ private function updateAssertStatusCall(MethodCall $methodCall): ?MethodCall
210224
401 => 'assertUnauthorized',
211225
403 => 'assertForbidden',
212226
404 => 'assertNotFound',
227+
405 => 'assertMethodNotAllowed',
213228
410 => 'assertGone',
214229
422 => 'assertUnprocessable',
215230
500 => 'assertInternalServerError',
@@ -230,6 +245,7 @@ private function updateAssertStatusCall(MethodCall $methodCall): ?MethodCall
230245
'HTTP_UNAUTHORIZED' => 'assertUnauthorized',
231246
'HTTP_FORBIDDEN' => 'assertForbidden',
232247
'HTTP_NOT_FOUND' => 'assertNotFound',
248+
'HTTP_METHOD_NOT_ALLOWED' => 'assertMethodNotAllowed',
233249
'HTTP_GONE' => 'assertGone',
234250
'HTTP_UNPROCESSABLE_ENTITY' => 'assertUnprocessable',
235251
'HTTP_INTERNAL_SERVER_ERROR' => 'assertInternalServerError',

tests/Rector/MethodCall/AssertStatusToAssertMethodRector/Fixture/fixture_with_illuminate_response_constants.php.inc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ class FixtureWithIlluminateTest
2424
$response->assertStatus(\Symfony\Component\HttpFoundation\Response::HTTP_NOT_FOUND);
2525
}
2626

27+
public function testMethodNotAllowed(\Illuminate\Testing\TestResponse $response)
28+
{
29+
$response->assertStatus(\Symfony\Component\HttpFoundation\Response::HTTP_METHOD_NOT_ALLOWED);
30+
}
31+
2732
public function testUnauthorized(\Illuminate\Testing\TestResponse $response)
2833
{
2934
$response->assertStatus(\Symfony\Component\HttpFoundation\Response::HTTP_UNAUTHORIZED);
@@ -78,6 +83,11 @@ class FixtureWithIlluminateTest
7883
$response->assertNotFound();
7984
}
8085

86+
public function testMethodNotAllowed(\Illuminate\Testing\TestResponse $response)
87+
{
88+
$response->assertMethodNotAllowed();
89+
}
90+
8191
public function testUnauthorized(\Illuminate\Testing\TestResponse $response)
8292
{
8393
$response->assertUnauthorized();

tests/Rector/MethodCall/AssertStatusToAssertMethodRector/Fixture/fixture_with_magic_numbers.php.inc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ class FixtureTest
2424
$response->assertStatus(404);
2525
}
2626

27+
public function testMethodNotAllowed(\Illuminate\Testing\TestResponse $response)
28+
{
29+
$response->assertStatus(405);
30+
}
31+
2732
public function testUnauthorized(\Illuminate\Testing\TestResponse $response)
2833
{
2934
$response->assertStatus(401);
@@ -78,6 +83,11 @@ class FixtureTest
7883
$response->assertNotFound();
7984
}
8085

86+
public function testMethodNotAllowed(\Illuminate\Testing\TestResponse $response)
87+
{
88+
$response->assertMethodNotAllowed();
89+
}
90+
8191
public function testUnauthorized(\Illuminate\Testing\TestResponse $response)
8292
{
8393
$response->assertUnauthorized();

tests/Rector/MethodCall/AssertStatusToAssertMethodRector/Fixture/fixture_with_symfony_response_constants.php.inc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ class FixtureWithSymfonyResponseTest
2424
$response->assertStatus(\Symfony\Component\HttpFoundation\Response::HTTP_NOT_FOUND);
2525
}
2626

27+
public function testMethodNotAllowed(\Illuminate\Testing\TestResponse $response)
28+
{
29+
$response->assertStatus(\Symfony\Component\HttpFoundation\Response::HTTP_METHOD_NOT_ALLOWED);
30+
}
31+
2732
public function testUnauthorized(\Illuminate\Testing\TestResponse $response)
2833
{
2934
$response->assertStatus(\Symfony\Component\HttpFoundation\Response::HTTP_UNAUTHORIZED);
@@ -63,6 +68,11 @@ class FixtureWithSymfonyResponseTest
6368
$response->assertNotFound();
6469
}
6570

71+
public function testMethodNotAllowed(\Illuminate\Testing\TestResponse $response)
72+
{
73+
$response->assertMethodNotAllowed();
74+
}
75+
6676
public function testUnauthorized(\Illuminate\Testing\TestResponse $response)
6777
{
6878
$response->assertUnauthorized();

0 commit comments

Comments
 (0)