Skip to content

Commit

Permalink
Fix deprecated method use in RoutingFilter.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Nov 16, 2017
1 parent 019f0d4 commit 2469efc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/Routing/Filter/RoutingFilter.php
Expand Up @@ -64,8 +64,8 @@ public function beforeDispatch(Event $event)
$event->stopPropagation();
/* @var \Cake\Http\Response $response */
$response = $event->getData('response');
$response->statusCode($e->getCode());
$response->header('Location', $e->getMessage());
$response = $response->withStatus($e->getCode())
->withLocation($e->getMessage());

return $response;
}
Expand Down
44 changes: 22 additions & 22 deletions tests/TestCase/Routing/Filter/RoutingFilterTest.php
Expand Up @@ -37,13 +37,15 @@ public function testBeforeDispatchSkipWhenControllerSet()
{
$filter = new RoutingFilter();

$request = new ServerRequest('/testcontroller/testaction/params1/params2/params3');
$request->addParams(['controller' => 'articles']);
$request = new ServerRequest([
'url' => '/testcontroller/testaction/params1/params2/params3',
'params' => ['controller' => 'articles']
]);
$event = new Event(__CLASS__, $this, compact('request'));
$filter->beforeDispatch($event);

$this->assertSame($request->params['controller'], 'articles');
$this->assertEmpty($request->params['action']);
$this->assertSame($request->getParam('controller'), 'articles');
$this->assertEmpty($request->getParam('action'));
}

/**
Expand All @@ -61,12 +63,11 @@ public function testBeforeDispatchSetsParameters()
$event = new Event(__CLASS__, $this, compact('request'));
$filter->beforeDispatch($event);

$this->assertSame($request->params['controller'], 'testcontroller');
$this->assertSame($request->params['action'], 'testaction');
$this->assertSame($request->params['pass'][0], 'params1');
$this->assertSame($request->params['pass'][1], 'params2');
$this->assertSame($request->params['pass'][2], 'params3');
$this->assertFalse(!empty($request['form']));
$this->assertSame($request->getParam('controller'), 'testcontroller');
$this->assertSame($request->getParam('action'), 'testaction');
$this->assertSame($request->getParam('pass.0'), 'params1');
$this->assertSame($request->getParam('pass.1'), 'params2');
$this->assertSame($request->getParam('pass.2'), 'params3');
}

/**
Expand All @@ -88,8 +89,8 @@ public function testBeforeDispatchRedirectRoute()
$event = new Event(__CLASS__, $this, compact('request', 'response'));
$response = $filter->beforeDispatch($event);
$this->assertInstanceOf('Cake\Http\Response', $response);
$this->assertSame('http://localhost/articles', $response->header()['Location']);
$this->assertSame(301, $response->statusCode());
$this->assertSame('http://localhost/articles', $response->getHeaderLine('Location'));
$this->assertSame(301, $response->getStatusCode());
$this->assertTrue($event->isStopped());
}

Expand All @@ -114,20 +115,19 @@ public function testQueryStringOnRoot()
$event = new Event(__CLASS__, $this, compact('request'));
$filter->beforeDispatch($event);

$this->assertRegExp('/posts/', $request['controller']);
$this->assertRegExp('/home/', $request['action']);
$this->assertTrue(isset($request['url']['sleep']));
$this->assertTrue(isset($request['url']['coffee']));
$this->assertRegExp('/posts/', $request->getParam('controller'));
$this->assertRegExp('/home/', $request->getParam('action'));
$this->assertSame('sissies', $request->getQuery('sleep'));
$this->assertSame('life', $request->getQuery('coffee'));

$request = new ServerRequest('/?coffee=life&sleep=sissy');

$event = new Event(__CLASS__, $this, compact('request'));
$filter->beforeDispatch($event);

$this->assertRegExp('/pages/', $request['controller']);
$this->assertRegExp('/display/', $request['action']);
$this->assertTrue(isset($request['url']['sleep']));
$this->assertTrue(isset($request['url']['coffee']));
$this->assertEquals('life', $request['url']['coffee']);
$this->assertRegExp('/pages/', $request->getParam('controller'));
$this->assertRegExp('/display/', $request->getParam('action'));
$this->assertSame('sissy', $request->getQuery('sleep'));
$this->assertSame('life', $request->getQuery('coffee'));
$this->assertEquals('life', $request->getQuery('coffee'));
}
}

0 comments on commit 2469efc

Please sign in to comment.