Skip to content

Commit

Permalink
Fix up tests for deprecated methods.
Browse files Browse the repository at this point in the history
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 8563702
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tests/TestCase/Routing/Filter/RoutingFilterTest.php
Expand Up @@ -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());
}

Expand Down
19 changes: 19 additions & 0 deletions tests/TestCase/Routing/RouterTest.php
Expand Up @@ -134,6 +134,7 @@ public function testRouteDefaultParams()
*/
public function testMapResources()
{
$restore = error_reporting(E_ALL ^ E_USER_DEPRECATED);
Router::mapResources('Posts');

$expected = [
Expand Down Expand Up @@ -224,6 +225,7 @@ public function testMapResources()
];
$result = Router::parse('/posts/name', 'PUT');
$this->assertEquals($expected, $result);
error_reporting($restore);
}

/**
Expand All @@ -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');
Expand All @@ -255,6 +258,7 @@ public function testPluginMapResources()
'_method' => 'GET',
];
$this->assertEquals($expected, $result);
error_reporting($restore);
}

/**
Expand All @@ -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');
Expand All @@ -277,6 +282,7 @@ public function testMapResourcesWithPrefix()
'_method' => 'GET',
];
$this->assertEquals($expected, $result);
error_reporting($restore);
}

/**
Expand All @@ -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']);

Expand All @@ -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' => [
Expand All @@ -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);
}

/**
Expand All @@ -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');
Expand All @@ -358,6 +369,7 @@ public function testPluginMapResourcesWithPrefix()
'prefix' => 'api',
];
$this->assertEquals($expected, $result);
error_reporting($restore);
}

/**
Expand Down Expand Up @@ -397,6 +409,7 @@ public function testMultipleResourceRoute()
*/
public function testGenerateUrlResourceRoute()
{
$restore = error_reporting(E_ALL ^ E_USER_DEPRECATED);
Router::mapResources('Posts');

$result = Router::url([
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -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',
Expand Down Expand Up @@ -2782,6 +2800,7 @@ public function testParseNamedParameters()
]
];
$this->assertEquals($expected, $request->params);
error_reporting($restore);
}

/**
Expand Down

0 comments on commit 8563702

Please sign in to comment.