From 5e2dd014f530baccc81f0209cbf69c5137673827 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 30 Sep 2026 03:18:04 +0000 Subject: [PATCH] refactor(testing): remove the L4.2 response assertions (task 2.17) Delete Foundation\Testing\AssertionsTrait (assertResponseOk, assertResponseStatus, assertRedirectedTo/ToRoute/ToAction, assertViewHas/HasAll/Missing, assertSessionHas/HasAll/HasErrors, assertHasOldInput). They read $this->client->getResponse() and have v13 equivalents on the TestResponse that call() returns since 4.2.112; the dicoding app no longer calls them. v13's Foundation TestCase has no such methods either, so this removes an API that the foundation flip (4.5) would otherwise have to carry. Callers now fail with a missing-method error instead of passing silently. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_0169SsatCE8LhaTsQTPiGtVo --- .../Foundation/Testing/AssertionsTrait.php | 223 ------------------ .../Foundation/Testing/TestCase.php | 2 +- .../FoundationTestingResponseTest.php | 12 +- 3 files changed, 2 insertions(+), 235 deletions(-) delete mode 100644 src/Illuminate/Foundation/Testing/AssertionsTrait.php diff --git a/src/Illuminate/Foundation/Testing/AssertionsTrait.php b/src/Illuminate/Foundation/Testing/AssertionsTrait.php deleted file mode 100644 index 218595bb8..000000000 --- a/src/Illuminate/Foundation/Testing/AssertionsTrait.php +++ /dev/null @@ -1,223 +0,0 @@ -client->getResponse(); - - $actual = $response->getStatusCode(); - - return $this->assertTrue($response->isOk(), 'Expected status code 200, got ' .$actual); - } - - /** - * Assert that the client response has a given code. - * - * @param int $code - * @return void - */ - public function assertResponseStatus($code) - { - return $this->assertEquals($code, $this->client->getResponse()->getStatusCode()); - } - - /** - * Assert that the response view has a given piece of bound data. - * - * @param string|array $key - * @param mixed $value - * @return void - */ - public function assertViewHas($key, $value = null) - { - if (is_array($key)) return $this->assertViewHasAll($key); - - $response = $this->client->getResponse(); - - if ( ! isset($response->original) || ! $response->original instanceof View) - { - return $this->assertTrue(false, 'The response was not a view.'); - } - - if (is_null($value)) - { - $this->assertArrayHasKey($key, $response->original->getData()); - } - else - { - $this->assertEquals($value, $response->original->$key); - } - } - - /** - * Assert that the view has a given list of bound data. - * - * @param array $bindings - * @return void - */ - public function assertViewHasAll(array $bindings) - { - foreach ($bindings as $key => $value) - { - if (is_int($key)) - { - $this->assertViewHas($value); - } - else - { - $this->assertViewHas($key, $value); - } - } - } - - /** - * Assert that the response view is missing a piece of bound data. - * - * @param string $key - * @return void - */ - public function assertViewMissing($key) - { - $response = $this->client->getResponse(); - - if ( ! isset($response->original) || ! $response->original instanceof View) - { - return $this->assertTrue(false, 'The response was not a view.'); - } - - $this->assertArrayNotHasKey($key, $response->original->getData()); - } - - /** - * Assert whether the client was redirected to a given URI. - * - * @param string $uri - * @param array $with - * @return void - */ - public function assertRedirectedTo($uri, $with = array()) - { - $response = $this->client->getResponse(); - - $this->assertInstanceOf('Illuminate\Http\RedirectResponse', $response); - - $this->assertEquals($this->app['url']->to($uri), $response->headers->get('Location')); - - $this->assertSessionHasAll($with); - } - - /** - * Assert whether the client was redirected to a given route. - * - * @param string $name - * @param array $parameters - * @param array $with - * @return void - */ - public function assertRedirectedToRoute($name, $parameters = array(), $with = array()) - { - $this->assertRedirectedTo($this->app['url']->route($name, $parameters), $with); - } - - /** - * Assert whether the client was redirected to a given action. - * - * @param string $name - * @param array $parameters - * @param array $with - * @return void - */ - public function assertRedirectedToAction($name, $parameters = array(), $with = array()) - { - $this->assertRedirectedTo($this->app['url']->action($name, $parameters), $with); - } - - /** - * Assert that the session has a given list of values. - * - * @param string|array $key - * @param mixed $value - * @return void - */ - public function assertSessionHas($key, $value = null) - { - if (is_array($key)) return $this->assertSessionHasAll($key); - - if (is_null($value)) - { - $this->assertTrue($this->app['session.store']->has($key), "Session missing key: $key"); - } - else - { - $this->assertEquals($value, $this->app['session.store']->get($key)); - } - } - - /** - * Assert that the session has a given list of values. - * - * @param array $bindings - * @return void - */ - public function assertSessionHasAll(array $bindings) - { - foreach ($bindings as $key => $value) - { - if (is_int($key)) - { - $this->assertSessionHas($value); - } - else - { - $this->assertSessionHas($key, $value); - } - } - } - - /** - * Assert that the session has errors bound. - * - * @param string|array $bindings - * @param mixed $format - * @return void - */ - public function assertSessionHasErrors($bindings = array(), $format = null) - { - $this->assertSessionHas('errors'); - - $bindings = (array) $bindings; - - $errors = $this->app['session.store']->get('errors'); - - foreach ($bindings as $key => $value) - { - if (is_int($key)) - { - $this->assertTrue($errors->has($value), "Session missing error: $value"); - } - else - { - $this->assertContains($value, $errors->get($key, $format)); - } - } - } - - /** - * Assert that the session has old input. - * - * @return void - */ - public function assertHasOldInput() - { - $this->assertSessionHas('_old_input'); - } - -} diff --git a/src/Illuminate/Foundation/Testing/TestCase.php b/src/Illuminate/Foundation/Testing/TestCase.php index 27ea815d8..e6aa723ca 100755 --- a/src/Illuminate/Foundation/Testing/TestCase.php +++ b/src/Illuminate/Foundation/Testing/TestCase.php @@ -2,7 +2,7 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase { - use ApplicationTrait, AssertionsTrait; + use ApplicationTrait; /** * Setup the test environment. diff --git a/tests/Foundation/FoundationTestingResponseTest.php b/tests/Foundation/FoundationTestingResponseTest.php index 99687713b..395e66d73 100644 --- a/tests/Foundation/FoundationTestingResponseTest.php +++ b/tests/Foundation/FoundationTestingResponseTest.php @@ -2,7 +2,6 @@ use Illuminate\Foundation\Application; use Illuminate\Foundation\Testing\ApplicationTrait; -use Illuminate\Foundation\Testing\AssertionsTrait; use Illuminate\Http\JsonResponse; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; @@ -19,7 +18,7 @@ class FoundationTestingResponseTest extends TestCase { - use ApplicationTrait, AssertionsTrait; + use ApplicationTrait; protected function setUp(): void { @@ -52,15 +51,6 @@ public function testCallReturnsATestResponseAroundTheClientResponse() $response->assertOk()->assertSee('hello')->assertHeader('X-Foo', 'bar'); } - public function testLegacyAssertionsStillReadTheClientResponse() - { - $this->client->response = new Response('created', 201); - - $this->call('POST', '/things'); - - $this->assertResponseStatus(201); - } - public function testFailedFluentAssertionIsAPhpunitFailure() { $this->client->response = new Response('missing', 404);