From 856370297db9b742ab08bd6fafc49fdbde5d6f75 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Thu, 24 Mar 2016 22:53:17 -0400 Subject: [PATCH] Fix up tests for deprecated methods. I'm not a fan of messing around with the error_reporting level, but PHPUnit doesn't give us many better options. --- .../Routing/Filter/RoutingFilterTest.php | 8 +++++--- tests/TestCase/Routing/RouterTest.php | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/tests/TestCase/Routing/Filter/RoutingFilterTest.php b/tests/TestCase/Routing/Filter/RoutingFilterTest.php index 9e698463ad1..b8f73c8e45b 100644 --- a/tests/TestCase/Routing/Filter/RoutingFilterTest.php +++ b/tests/TestCase/Routing/Filter/RoutingFilterTest.php @@ -77,8 +77,10 @@ public function testBeforeDispatchSetsParameters() */ public function testBeforeDispatchRedirectRoute() { - Router::redirect('/home', ['controller' => 'articles']); - Router::connect('/:controller/:action/*'); + Router::scope('/', function ($routes) { + $routes->redirect('/home', ['controller' => 'articles']); + $routes->connect('/:controller/:action/*'); + }); $filter = new RoutingFilter(); $request = new Request("/home"); @@ -86,7 +88,7 @@ public function testBeforeDispatchRedirectRoute() $event = new Event(__CLASS__, $this, compact('request', 'response')); $response = $filter->beforeDispatch($event); $this->assertInstanceOf('Cake\Network\Response', $response); - $this->assertSame('http://localhost/articles/index', $response->header()['Location']); + $this->assertSame('http://localhost/articles', $response->header()['Location']); $this->assertSame(301, $response->statusCode()); } diff --git a/tests/TestCase/Routing/RouterTest.php b/tests/TestCase/Routing/RouterTest.php index 1425ac294c9..0067c45f1a7 100644 --- a/tests/TestCase/Routing/RouterTest.php +++ b/tests/TestCase/Routing/RouterTest.php @@ -134,6 +134,7 @@ public function testRouteDefaultParams() */ public function testMapResources() { + $restore = error_reporting(E_ALL ^ E_USER_DEPRECATED); Router::mapResources('Posts'); $expected = [ @@ -224,6 +225,7 @@ public function testMapResources() ]; $result = Router::parse('/posts/name', 'PUT'); $this->assertEquals($expected, $result); + error_reporting($restore); } /** @@ -233,6 +235,7 @@ public function testMapResources() */ public function testPluginMapResources() { + $restore = error_reporting(E_ALL ^ E_USER_DEPRECATED); Router::mapResources('TestPlugin.TestPlugin'); $result = Router::parse('/test_plugin/test_plugin', 'GET'); @@ -255,6 +258,7 @@ public function testPluginMapResources() '_method' => 'GET', ]; $this->assertEquals($expected, $result); + error_reporting($restore); } /** @@ -264,6 +268,7 @@ public function testPluginMapResources() */ public function testMapResourcesWithPrefix() { + $restore = error_reporting(E_ALL ^ E_USER_DEPRECATED); Router::mapResources('Posts', ['prefix' => 'api']); $result = Router::parse('/api/posts', 'GET'); @@ -277,6 +282,7 @@ public function testMapResourcesWithPrefix() '_method' => 'GET', ]; $this->assertEquals($expected, $result); + error_reporting($restore); } /** @@ -286,6 +292,7 @@ public function testMapResourcesWithPrefix() */ public function testMapResourcesWithExtension() { + $restore = error_reporting(E_ALL ^ E_USER_DEPRECATED); Router::extensions(['json', 'xml'], false); Router::mapResources('Posts', ['_ext' => 'json']); @@ -306,6 +313,7 @@ public function testMapResourcesWithExtension() $result = Router::parse('/posts.xml', 'GET'); $this->assertArrayNotHasKey('_method', $result, 'Not an extension/resource route.'); + error_reporting($restore); } /** @@ -313,6 +321,7 @@ public function testMapResourcesWithExtension() */ public function testMapResourcesConnectOptions() { + $restore = error_reporting(E_ALL ^ E_USER_DEPRECATED); Plugin::load('TestPlugin'); Router::mapResources('Posts', [ 'connectOptions' => [ @@ -324,6 +333,7 @@ public function testMapResourcesConnectOptions() $route = $routes[0]; $this->assertInstanceOf('TestPlugin\Routing\Route\TestRoute', $route); $this->assertEquals('^(bar)$', $route->options['foo']); + error_reporting($restore); } /** @@ -333,6 +343,7 @@ public function testMapResourcesConnectOptions() */ public function testPluginMapResourcesWithPrefix() { + $restore = error_reporting(E_ALL ^ E_USER_DEPRECATED); Router::mapResources('TestPlugin.TestPlugin', ['prefix' => 'api']); $result = Router::parse('/api/test_plugin/test_plugin', 'GET'); @@ -358,6 +369,7 @@ public function testPluginMapResourcesWithPrefix() 'prefix' => 'api', ]; $this->assertEquals($expected, $result); + error_reporting($restore); } /** @@ -397,6 +409,7 @@ public function testMultipleResourceRoute() */ public function testGenerateUrlResourceRoute() { + $restore = error_reporting(E_ALL ^ E_USER_DEPRECATED); Router::mapResources('Posts'); $result = Router::url([ @@ -431,6 +444,7 @@ public function testGenerateUrlResourceRoute() $result = Router::url(['controller' => 'Posts', 'action' => 'edit', '_method' => 'PATCH', 'id' => 10]); $expected = '/posts/10'; $this->assertEquals($expected, $result); + error_reporting($restore); } /** @@ -2739,10 +2753,12 @@ public function testPatternOnAction() */ public function testRedirect() { + $restore = error_reporting(E_ALL ^ E_USER_DEPRECATED); Router::redirect('/mobile', '/', ['status' => 301]); $routes = Router::routes(); $route = $routes[0]; $this->assertInstanceOf('Cake\Routing\Route\RedirectRoute', $route); + error_reporting($restore); } /** @@ -2752,6 +2768,8 @@ public function testRedirect() */ public function testParseNamedParameters() { + $restore = error_reporting(E_ALL ^ E_USER_DEPRECATED); + $request = new Request(); $request->addParams([ 'controller' => 'posts', @@ -2782,6 +2800,7 @@ public function testParseNamedParameters() ] ]; $this->assertEquals($expected, $request->params); + error_reporting($restore); } /**