Browse Source

Use getter/setter instead of deprecated properties.

ADmad 7 years ago
parent
commit
a9a943a9dd

+ 1 - 1
src/View/Helper.php

@@ -116,7 +116,7 @@ class Helper implements EventListenerInterface
     public function __construct(View $View, array $config = [])
     {
         $this->_View = $View;
-        $this->request = $View->request;
+        $this->request = $View->getRequest();
 
         $this->setConfig($config);
 

+ 1 - 1
src/View/Helper/HtmlHelper.php

@@ -143,7 +143,7 @@ class HtmlHelper extends Helper
     public function __construct(View $View, array $config = [])
     {
         parent::__construct($View, $config);
-        $this->response = $this->_View->response ?: new Response();
+        $this->response = $this->_View->getResponse() ?: new Response();
     }
 
     /**

+ 1 - 1
src/View/HelperRegistry.php

@@ -144,7 +144,7 @@ class HelperRegistry extends ObjectRegistry implements EventDispatcherInterface
     protected function _create($class, $alias, $settings)
     {
         $instance = new $class($this->_View, $settings);
-        $vars = ['request', 'theme', 'plugin'];
+        $vars = ['theme', 'plugin'];
         foreach ($vars as $var) {
             $instance->{$var} = $this->_View->{$var};
         }

+ 4 - 5
tests/TestCase/View/Helper/FlashHelperTest.php

@@ -37,9 +37,8 @@ class FlashHelperTest extends TestCase
     public function setUp()
     {
         parent::setUp();
-        $this->View = new View();
         $session = new Session();
-        $this->View->request = new ServerRequest(['session' => $session]);
+        $this->View = new View(new ServerRequest(['session' => $session]));
         $this->Flash = new FlashHelper($this->View);
 
         $session->write([
@@ -143,7 +142,7 @@ class FlashHelperTest extends TestCase
     public function testFlashThrowsException()
     {
         $this->expectException(\UnexpectedValueException::class);
-        $this->View->request->getSession()->write('Flash.foo', 'bar');
+        $this->View->getRequest()->getSession()->write('Flash.foo', 'bar');
         $this->Flash->render('foo');
     }
 
@@ -217,7 +216,7 @@ class FlashHelperTest extends TestCase
             ['div' => ['id' => 'classy-message']], 'Recorded', '/div'
         ];
         $this->assertHtml($expected, $result);
-        $this->assertNull($this->View->request->getSession()->read('Flash.stack'));
+        $this->assertNull($this->View->getRequest()->getSession()->read('Flash.stack'));
     }
 
     /**
@@ -228,7 +227,7 @@ class FlashHelperTest extends TestCase
      */
     public function testFlashWithPrefix()
     {
-        $this->View->request = $this->View->request->withParam('prefix', 'Admin');
+        $this->View->setRequest($this->View->getRequest()->withParam('prefix', 'Admin'));
         $result = $this->Flash->render('flash');
         $expected = 'flash element from Admin prefix folder';
         $this->assertContains($expected, $result);

+ 5 - 5
tests/TestCase/View/JsonViewTest.php

@@ -293,15 +293,15 @@ class JsonViewTest extends TestCase
         $output = $View->render(false);
 
         $this->assertSame(json_encode($data), $output);
-        $this->assertSame('application/json', $View->response->getType());
+        $this->assertSame('application/json', $View->getResponse()->getType());
 
-        $View->request = $View->request->withQueryParams(['callback' => 'jfunc']);
+        $View->request = $View->getRequest()->withQueryParams(['callback' => 'jfunc']);
         $output = $View->render(false);
         $expected = 'jfunc(' . json_encode($data) . ')';
         $this->assertSame($expected, $output);
-        $this->assertSame('application/javascript', $View->response->getType());
+        $this->assertSame('application/javascript', $View->getResponse()->getType());
 
-        $View->request = $View->request->withQueryParams(['jsonCallback' => 'jfunc']);
+        $View->request = $View->getRequest()->withQueryParams(['jsonCallback' => 'jfunc']);
         $View->viewVars['_jsonp'] = 'jsonCallback';
         $output = $View->render(false);
         $expected = 'jfunc(' . json_encode($data) . ')';
@@ -337,6 +337,6 @@ class JsonViewTest extends TestCase
 
         $expected = json_encode(['user' => 'fake', 'list' => ['item1', 'item2'], 'paging' => null]);
         $this->assertSame($expected, $output);
-        $this->assertSame('application/json', $View->response->getType());
+        $this->assertSame('application/json', $View->getResponse()->getType());
     }
 }

+ 2 - 2
tests/TestCase/View/ViewBuilderTest.php

@@ -247,8 +247,8 @@ class ViewBuilderTest extends TestCase
         $this->assertEquals('Admin/', $view->getLayoutPath());
         $this->assertEquals('TestPlugin', $view->plugin);
         $this->assertEquals('TestTheme', $view->theme);
-        $this->assertSame($request, $view->request);
-        $this->assertInstanceOf(Response::class, $view->response);
+        $this->assertSame($request, $view->getRequest());
+        $this->assertInstanceOf(Response::class, $view->getResponse());
         $this->assertSame($events, $view->getEventManager());
         $this->assertSame(['one' => 'value'], $view->viewVars);
         $this->assertInstanceOf('Cake\View\Helper\HtmlHelper', $view->Html);

+ 5 - 5
tests/TestCase/View/XmlViewTest.php

@@ -52,7 +52,7 @@ class XmlViewTest extends TestCase
         $output = $View->render(false);
 
         $this->assertSame(Xml::build($data)->asXML(), $output);
-        $this->assertSame('application/xml', $View->response->getType());
+        $this->assertSame('application/xml', $View->getResponse()->getType());
 
         $data = [
             [
@@ -191,7 +191,7 @@ class XmlViewTest extends TestCase
         $Controller->set('_serialize', ['no', 'user']);
         $Controller->viewBuilder()->setClassName('Xml');
         $View = $Controller->createView();
-        $this->assertSame('application/xml', $View->response->getType());
+        $this->assertSame('application/xml', $View->getResponse()->getType());
         $output = $View->render(false);
         $expected = [
             'response' => ['no' => $data['no'], 'user' => $data['user']]
@@ -223,7 +223,7 @@ class XmlViewTest extends TestCase
         $Controller->set('_serialize', ['new_name' => 'original_name', 'user']);
         $Controller->viewBuilder()->setClassName('Xml');
         $View = $Controller->createView();
-        $this->assertSame('application/xml', $View->response->getType());
+        $this->assertSame('application/xml', $View->getResponse()->getType());
         $output = $View->render(false);
         $expected = [
             'response' => ['new_name' => $data['original_name'], 'user' => $data['user']]
@@ -257,7 +257,7 @@ class XmlViewTest extends TestCase
         $output = $View->render();
 
         $this->assertSame(Xml::build($data)->asXML(), $output);
-        $this->assertSame('application/xml', $View->response->getType());
+        $this->assertSame('application/xml', $View->getResponse()->getType());
 
         $data = ['no' => 'nope', 'user' => 'fake', 'list' => ['item1', 'item2']];
         $Controller->viewVars = [];
@@ -306,7 +306,7 @@ class XmlViewTest extends TestCase
         ];
         $expected = Xml::build($expected)->asXML();
         $this->assertSame($expected, $output);
-        $this->assertSame('application/xml', $View->response->getType());
+        $this->assertSame('application/xml', $View->getResponse()->getType());
         $this->assertInstanceOf('Cake\View\HelperRegistry', $View->helpers());
     }
 }