From a8665a0ddd4c4367c98906f498295b7f2b71c47b Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 13 Nov 2017 11:42:17 -0500 Subject: [PATCH] Update test controllers to use undeprecated APIs. --- tests/Fixture/AssertIntegrationTestCase.php | 2 +- .../Controller/RequestActionController.php | 59 ++++++------------- .../Controller/TestsAppsController.php | 12 ++-- 3 files changed, 24 insertions(+), 49 deletions(-) diff --git a/tests/Fixture/AssertIntegrationTestCase.php b/tests/Fixture/AssertIntegrationTestCase.php index 87413add516..7d810b0deef 100644 --- a/tests/Fixture/AssertIntegrationTestCase.php +++ b/tests/Fixture/AssertIntegrationTestCase.php @@ -18,7 +18,7 @@ class AssertIntegrationTestCase extends IntegrationTestCase public function testBadAssertNoRedirect() { $this->_response = new Response(); - $this->_response->header('Location', 'http://localhost/tasks/index'); + $this->_response = $this->_response->withLocation('http://localhost/tasks/index'); $this->assertNoRedirect(); } diff --git a/tests/test_app/TestApp/Controller/RequestActionController.php b/tests/test_app/TestApp/Controller/RequestActionController.php index 840cd1072e4..ea52ac7bea3 100644 --- a/tests/test_app/TestApp/Controller/RequestActionController.php +++ b/tests/test_app/TestApp/Controller/RequestActionController.php @@ -35,9 +35,7 @@ class RequestActionController extends AppController */ public function test_request_action() { - $this->response->body('This is a test'); - - return $this->response; + return $this->response->withStringBody('This is a test'); } /** @@ -49,9 +47,7 @@ public function test_request_action() */ public function another_ra_test($id, $other) { - $this->response->body($id + $other); - - return $this->response; + return $this->response->withStringBody($id + $other); } /** @@ -61,9 +57,7 @@ public function another_ra_test($id, $other) */ public function normal_request_action() { - $this->response->body('Hello World'); - - return $this->response; + return $this->response->withStringBody('Hello World'); } /** @@ -73,9 +67,7 @@ public function normal_request_action() */ public function return_here() { - $this->response->body($this->here); - - return $this->response; + return $this->response->withStringBody($this->here); } /** @@ -96,9 +88,7 @@ public function paginate_request_action() */ public function post_pass() { - $this->response->body(json_encode($this->request->data)); - - return $this->response; + return $this->response->withStringBody(json_encode($this->request->data)); } /** @@ -108,9 +98,7 @@ public function post_pass() */ public function query_pass() { - $this->response->body(json_encode($this->request->query)); - - return $this->response; + return $this->response->withStringBody(json_encode($this->request->query)); } /** @@ -120,9 +108,7 @@ public function query_pass() */ public function cookie_pass() { - $this->response->body(json_encode($this->request->cookies)); - - return $this->response; + return $this->response->withStringBody(json_encode($this->request->cookies)); } /** @@ -132,18 +118,15 @@ public function cookie_pass() */ public function params_pass() { - $this->response->body(json_encode([ - 'params' => $this->request->params, - 'base' => $this->request->base, - 'here' => $this->request->here, - 'webroot' => $this->request->webroot, - 'params' => $this->request->params, - 'query' => $this->request->query, - 'url' => $this->request->url, + return $this->response->withStringBody(json_encode([ + 'params' => $this->request->getAttribute('params'), + 'base' => $this->request->getAttribute('base'), + 'here' => $this->request->getRequestTarget(), + 'webroot' => $this->request->getAttribute('webroot'), + 'query' => $this->request->getQueryParams(), + 'url' => $this->request->getUri()->getPath(), 'contentType' => $this->request->contentType(), ])); - - return $this->response; } /** @@ -155,12 +138,10 @@ public function param_check() { $this->autoRender = false; $content = ''; - if (isset($this->request->params[0])) { + if ($this->request->getParam('0')) { $content = 'return found'; } - $this->response->body($content); - - return $this->response; + return $this->response->withStringBody($content); } /** @@ -170,9 +151,7 @@ public function param_check() */ public function session_test() { - $this->response->body($this->request->session()->read('foo')); - - return $this->response; + return $this->response->withStringBody($this->request->getSession()->read('foo')); } /** @@ -182,9 +161,9 @@ public function session_test() */ public function input_test() { - $this->response->body($this->request->input('json_decode')->hello); + $text = $this->request->input('json_decode')->hello; - return $this->response; + return $this->response->withStringBody($text); } /** diff --git a/tests/test_app/TestApp/Controller/TestsAppsController.php b/tests/test_app/TestApp/Controller/TestsAppsController.php index 19444ed77cd..c0bbebe5414 100644 --- a/tests/test_app/TestApp/Controller/TestsAppsController.php +++ b/tests/test_app/TestApp/Controller/TestsAppsController.php @@ -31,17 +31,15 @@ class TestsAppsController extends AppController public function index() { $var = ''; - if (isset($this->request->query['var'])) { - $var = $this->request->query['var']; + if ($this->request->getQuery('var')) { + $var = $this->request->getQuery('var'); } $this->set('var', $var); } public function some_method() { - $this->response->body(5); - - return $this->response; + return $this->response->withStringBody(5); } public function set_action() @@ -62,9 +60,7 @@ public function redirect_to_permanent() public function set_type() { - $this->response->type('json'); - - return $this->response; + return $this->response->withType('json'); } public function throw_exception()