Skip to content

Commit

Permalink
Use getter/setter instead of deprecated properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Jun 4, 2018
1 parent 47d51c3 commit a9a943a
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/View/Helper.php
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/View/Helper/HtmlHelper.php
Expand Up @@ -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();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/View/HelperRegistry.php
Expand Up @@ -144,7 +144,7 @@ protected function _throwMissingClassError($class, $plugin)
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};
}
Expand Down
9 changes: 4 additions & 5 deletions tests/TestCase/View/Helper/FlashHelperTest.php
Expand Up @@ -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([
Expand Down Expand Up @@ -143,7 +142,7 @@ public function testFlash()
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');
}

Expand Down Expand Up @@ -217,7 +216,7 @@ public function testFlashWithStack()
['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'));
}

/**
Expand All @@ -228,7 +227,7 @@ public function testFlashWithStack()
*/
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);
Expand Down
10 changes: 5 additions & 5 deletions tests/TestCase/View/JsonViewTest.php
Expand Up @@ -293,15 +293,15 @@ public function testJsonpResponse()
$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) . ')';
Expand Down Expand Up @@ -337,6 +337,6 @@ public function testRenderWithView()

$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());
}
}
4 changes: 2 additions & 2 deletions tests/TestCase/View/ViewBuilderTest.php
Expand Up @@ -247,8 +247,8 @@ public function testBuildComplete()
$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);
Expand Down
10 changes: 5 additions & 5 deletions tests/TestCase/View/XmlViewTest.php
Expand Up @@ -52,7 +52,7 @@ public function testRenderWithoutView()
$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 = [
[
Expand Down Expand Up @@ -191,7 +191,7 @@ public function testRenderWithoutViewMultiple()
$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']]
Expand Down Expand Up @@ -223,7 +223,7 @@ public function testRenderWithoutViewMultipleAndAlias()
$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']]
Expand Down Expand Up @@ -257,7 +257,7 @@ public function testRenderWithSerializeTrue()
$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 = [];
Expand Down Expand Up @@ -306,7 +306,7 @@ public function testRenderWithView()
];
$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());
}
}

0 comments on commit a9a943a

Please sign in to comment.