Browse Source

Update test controllers to use undeprecated APIs.

mark_story 8 years ago
parent
commit
a8665a0ddd

+ 1 - 1
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();
     }

+ 19 - 40
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 @@ class RequestActionController extends AppController
      */
     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 @@ class RequestActionController extends AppController
      */
     public function normal_request_action()
     {
-        $this->response->body('Hello World');
-
-        return $this->response;
+        return $this->response->withStringBody('Hello World');
     }
 
     /**
@@ -73,9 +67,7 @@ class RequestActionController extends AppController
      */
     public function return_here()
     {
-        $this->response->body($this->here);
-
-        return $this->response;
+        return $this->response->withStringBody($this->here);
     }
 
     /**
@@ -96,9 +88,7 @@ class RequestActionController extends AppController
      */
     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 @@ class RequestActionController extends AppController
      */
     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 @@ class RequestActionController extends AppController
      */
     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 @@ class RequestActionController extends AppController
      */
     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 @@ class RequestActionController extends AppController
     {
         $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 @@ class RequestActionController extends AppController
      */
     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 @@ class RequestActionController extends AppController
      */
     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);
     }
 
     /**

+ 4 - 8
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 @@ class TestsAppsController extends AppController
 
     public function set_type()
     {
-        $this->response->type('json');
-
-        return $this->response;
+        return $this->response->withType('json');
     }
 
     public function throw_exception()