ソースを参照

Make Controller::$requeset and Controller::$response protected.

ADmad 8 年 前
コミット
79bbd00831

+ 2 - 4
src/Controller/Controller.php

@@ -111,18 +111,16 @@ class Controller implements EventListenerInterface, EventDispatcherInterface
      *
      * @var \Cake\Http\ServerRequest|null
      * @link https://book.cakephp.org/3.0/en/controllers/request-response.html#request
-     * @deprecated 3.6.0 The property will become protected in 4.0.0. Use getRequest()/setRequest instead.
      */
-    public $request;
+    protected $request;
 
     /**
      * An instance of a Response object that contains information about the impending response
      *
      * @var \Cake\Http\Response|null
      * @link https://book.cakephp.org/3.0/en/controllers/request-response.html#response
-     * @deprecated 3.6.0 The property will become protected in 4.0.0. Use getResponse()/setResponse instead.
      */
-    public $response;
+    protected $response;
 
     /**
      * The class name to use for creating the response object.

+ 9 - 9
tests/TestCase/Controller/ControllerTest.php

@@ -501,7 +501,7 @@ class ControllerTest extends TestCase
         $Controller = new Controller(null, new Response());
 
         $response = $Controller->redirect('http://cakephp.org', (int)$code);
-        $this->assertSame($response, $Controller->response);
+        $this->assertSame($response, $Controller->getResponse());
         $this->assertEquals($code, $response->getStatusCode());
         $this->assertEquals('http://cakephp.org', $response->getHeaderLine('Location'));
         $this->assertFalse($Controller->isAutoRenderEnabled());
@@ -561,7 +561,7 @@ class ControllerTest extends TestCase
 
         $result = $Controller->redirect('http://cakephp.org');
         $this->assertSame($newResponse, $result);
-        $this->assertSame($newResponse, $Controller->response);
+        $this->assertSame($newResponse, $Controller->getResponse());
     }
 
     /**
@@ -677,8 +677,8 @@ class ControllerTest extends TestCase
         $TestController = new TestController($request);
         $TestController->setAction('view', 1, 2);
         $expected = ['testId' => 1, 'test2Id' => 2];
-        $this->assertSame($expected, $TestController->request->getData());
-        $this->assertSame('view', $TestController->request->getParam('action'));
+        $this->assertSame($expected, $TestController->getRequest()->getData());
+        $this->assertSame('view', $TestController->getRequest()->getParam('action'));
     }
 
     /**
@@ -750,12 +750,12 @@ class ControllerTest extends TestCase
             ->getMock();
 
         $Controller = new Controller($request, $response);
-        $Controller->request = $Controller->request->withQueryParams([
+        $Controller->setRequest($Controller->getRequest()->withQueryParams([
             'posts' => [
                 'page' => 2,
                 'limit' => 2,
             ]
-        ]);
+        ]));
 
         $this->assertEquals([], $Controller->paginate);
 
@@ -770,7 +770,7 @@ class ControllerTest extends TestCase
         $this->assertInstanceOf('Cake\Datasource\ResultSetInterface', $results);
         $this->assertCount(3, $results);
 
-        $paging = $Controller->request->getParam('paging');
+        $paging = $Controller->getRequest()->getParam('paging');
         $this->assertSame($paging['Posts']['page'], 1);
         $this->assertSame($paging['Posts']['pageCount'], 1);
         $this->assertFalse($paging['Posts']['prevPage']);
@@ -781,7 +781,7 @@ class ControllerTest extends TestCase
         $this->assertInstanceOf('Cake\Datasource\ResultSetInterface', $results);
         $this->assertCount(1, $results);
 
-        $paging = $Controller->request->getParam('paging');
+        $paging = $Controller->getRequest()->getParam('paging');
         $this->assertSame($paging['Posts']['page'], 2);
         $this->assertSame($paging['Posts']['pageCount'], 2);
         $this->assertTrue($paging['Posts']['prevPage']);
@@ -929,7 +929,7 @@ class ControllerTest extends TestCase
         $result = $Controller->invokeAction();
         $this->assertEquals(
             ['testId' => '1', 'test2Id' => '2'],
-            $Controller->request->getData()
+            $Controller->getRequest()->getData()
         );
     }