Browse Source

Fix deprecated method use in View tests.

mark_story 8 years ago
parent
commit
32ef626982

+ 1 - 1
src/View/JsonView.php

@@ -113,7 +113,7 @@ class JsonView extends SerializedView
             }
             if ($this->request->getQuery($jsonpParam)) {
                 $return = sprintf('%s(%s)', h($this->request->getQuery($jsonpParam)), $return);
-                $this->response->type('js');
+                $this->response = $this->response->withType('js');
             }
         }
 

+ 2 - 3
src/View/SerializedView.php

@@ -46,11 +46,10 @@ abstract class SerializedView extends View
         EventManager $eventManager = null,
         array $viewOptions = []
     ) {
-        parent::__construct($request, $response, $eventManager, $viewOptions);
-
         if ($response && $response instanceof Response) {
-            $response->type($this->_responseType);
+            $response = $response->withType($this->_responseType);
         }
+        parent::__construct($request, $response, $eventManager, $viewOptions);
     }
 
     /**

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

@@ -293,13 +293,13 @@ class JsonViewTest extends TestCase
         $output = $View->render(false);
 
         $this->assertSame(json_encode($data), $output);
-        $this->assertSame('application/json', $Response->type());
+        $this->assertSame('application/json', $View->response->getType());
 
         $View->request->query = ['callback' => 'jfunc'];
         $output = $View->render(false);
         $expected = 'jfunc(' . json_encode($data) . ')';
         $this->assertSame($expected, $output);
-        $this->assertSame('application/javascript', $Response->type());
+        $this->assertSame('application/javascript', $View->response->getType());
 
         $View->request->query = ['jsonCallback' => 'jfunc'];
         $View->viewVars['_jsonp'] = 'jsonCallback';
@@ -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', $Response->type());
+        $this->assertSame('application/json', $View->response->getType());
     }
 }

+ 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', $Response->type());
+        $this->assertSame('application/xml', $View->response->getType());
 
         $data = [
             [
@@ -191,7 +191,7 @@ class XmlViewTest extends TestCase
         $Controller->set('_serialize', ['no', 'user']);
         $Controller->viewClass = 'Xml';
         $View = $Controller->createView();
-        $this->assertSame('application/xml', $Response->type());
+        $this->assertSame('application/xml', $View->response->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->viewClass = 'Xml';
         $View = $Controller->createView();
-        $this->assertSame('application/xml', $Response->type());
+        $this->assertSame('application/xml', $View->response->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', $Response->type());
+        $this->assertSame('application/xml', $View->response->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', $Response->type());
+        $this->assertSame('application/xml', $View->response->getType());
         $this->assertInstanceOf('Cake\View\HelperRegistry', $View->helpers());
     }
 }