Issue #2330751 by dawehner, chx: Fixed Random test failures everywhere due to ->with(Request::create()).
parent
e52aaf1e6c
commit
f3296754d1
|
@ -74,21 +74,21 @@ class UrlTest extends UnitTestCase {
|
||||||
public function testCreateFromPath() {
|
public function testCreateFromPath() {
|
||||||
$this->router->expects($this->at(0))
|
$this->router->expects($this->at(0))
|
||||||
->method('matchRequest')
|
->method('matchRequest')
|
||||||
->with(Request::create('/node'))
|
->with($this->getRequestConstraint('/node'))
|
||||||
->willReturn([
|
->willReturn([
|
||||||
RouteObjectInterface::ROUTE_NAME => 'view.frontpage.page_1',
|
RouteObjectInterface::ROUTE_NAME => 'view.frontpage.page_1',
|
||||||
'_raw_variables' => new ParameterBag(),
|
'_raw_variables' => new ParameterBag(),
|
||||||
]);
|
]);
|
||||||
$this->router->expects($this->at(1))
|
$this->router->expects($this->at(1))
|
||||||
->method('matchRequest')
|
->method('matchRequest')
|
||||||
->with(Request::create('/node/1'))
|
->with($this->getRequestConstraint('/node/1'))
|
||||||
->willReturn([
|
->willReturn([
|
||||||
RouteObjectInterface::ROUTE_NAME => 'node_view',
|
RouteObjectInterface::ROUTE_NAME => 'node_view',
|
||||||
'_raw_variables' => new ParameterBag(['node' => '1']),
|
'_raw_variables' => new ParameterBag(['node' => '1']),
|
||||||
]);
|
]);
|
||||||
$this->router->expects($this->at(2))
|
$this->router->expects($this->at(2))
|
||||||
->method('matchRequest')
|
->method('matchRequest')
|
||||||
->with(Request::create('/node/2/edit'))
|
->with($this->getRequestConstraint('/node/2/edit'))
|
||||||
->willReturn([
|
->willReturn([
|
||||||
RouteObjectInterface::ROUTE_NAME => 'node_edit',
|
RouteObjectInterface::ROUTE_NAME => 'node_edit',
|
||||||
'_raw_variables' => new ParameterBag(['node' => '2']),
|
'_raw_variables' => new ParameterBag(['node' => '2']),
|
||||||
|
@ -104,6 +104,21 @@ class UrlTest extends UnitTestCase {
|
||||||
return $urls;
|
return $urls;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This constraint checks whether a Request object has the right path.
|
||||||
|
*
|
||||||
|
* @param string $path
|
||||||
|
* The path.
|
||||||
|
*
|
||||||
|
* @return \PHPUnit_Framework_Constraint_Callback
|
||||||
|
* The constraint checks whether a Request object has the right path.
|
||||||
|
*/
|
||||||
|
protected function getRequestConstraint($path) {
|
||||||
|
return $this->callback(function (Request $request) use ($path) {
|
||||||
|
return $request->getPathInfo() == $path;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the createFromPath method with the special <front> path.
|
* Tests the createFromPath method with the special <front> path.
|
||||||
*
|
*
|
||||||
|
@ -124,7 +139,7 @@ class UrlTest extends UnitTestCase {
|
||||||
public function testCreateFromPathInvalid() {
|
public function testCreateFromPathInvalid() {
|
||||||
$this->router->expects($this->once())
|
$this->router->expects($this->once())
|
||||||
->method('matchRequest')
|
->method('matchRequest')
|
||||||
->with(Request::create('/non-existent'))
|
->with($this->getRequestConstraint('/non-existent'))
|
||||||
->will($this->throwException(new ResourceNotFoundException()));
|
->will($this->throwException(new ResourceNotFoundException()));
|
||||||
|
|
||||||
$this->assertNull(Url::createFromPath('non-existent'));
|
$this->assertNull(Url::createFromPath('non-existent'));
|
||||||
|
|
Loading…
Reference in New Issue