Skip to content
Permalink
Browse files

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.
  • Loading branch information...
markstory committed Mar 25, 2016
1 parent f288e4c commit 856370297db9b742ab08bd6fafc49fdbde5d6f75
Showing with 24 additions and 3 deletions.
  1. +5 −3 tests/TestCase/Routing/Filter/RoutingFilterTest.php
  2. +19 −0 tests/TestCase/Routing/RouterTest.php
@@ -77,16 +77,18 @@ 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");
$response = new Response();
$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());
}
@@ -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,13 +313,15 @@ public function testMapResourcesWithExtension()
$result = Router::parse('/posts.xml', 'GET');
$this->assertArrayNotHasKey('_method', $result, 'Not an extension/resource route.');
error_reporting($restore);
}
/**
* testMapResources with custom connectOptions
*/
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);
}
/**

0 comments on commit 8563702

Please sign in to comment.
You can’t perform that action at this time.