Skip to content

Commit

Permalink
Added delta for Request comparison
Browse files Browse the repository at this point in the history
Sometimes, tests are failing because REQUEST_TIME
changes between the creation of the various sub-requests.

By using delta, we allow maximum of second of difference.

Example: https://travis-ci.org/symfony/symfony/jobs/17668158#L511
  • Loading branch information
lavoiesl authored and fabpot committed Jan 27, 2014
1 parent 0cb789a commit 72d4583
Showing 1 changed file with 19 additions and 25 deletions.
Expand Up @@ -55,14 +55,7 @@ public function testRenderWithObjectsAsAttributes()
$subRequest->headers->set('x-forwarded-for', array('127.0.0.1'));
$subRequest->server->set('HTTP_X_FORWARDED_FOR', '127.0.0.1');

$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
$kernel
->expects($this->any())
->method('handle')
->with($subRequest)
;

$strategy = new InlineFragmentRenderer($kernel);
$strategy = new InlineFragmentRenderer($this->getKernelExpectingRequest($subRequest));

$strategy->render(new ControllerReference('main_controller', array('object' => $object), array()), Request::create('/'));
}
Expand All @@ -73,15 +66,7 @@ public function testRenderWithTrustedHeaderDisabled()

Request::setTrustedHeaderName(Request::HEADER_CLIENT_IP, '');

$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
$kernel
->expects($this->any())
->method('handle')
->with(Request::create('/'))
;

$strategy = new InlineFragmentRenderer($kernel);

$strategy = new InlineFragmentRenderer($this->getKernelExpectingRequest(Request::create('/')));
$strategy->render('/', Request::create('/'));

Request::setTrustedHeaderName(Request::HEADER_CLIENT_IP, $trustedHeaderName);
Expand Down Expand Up @@ -132,6 +117,22 @@ private function getKernel($returnValue)
return $kernel;
}

/**
* Creates a Kernel expecting a request equals to $request
* Allows delta in comparison in case REQUEST_TIME changed by 1 second
*/
private function getKernelExpectingRequest(Request $request)
{
$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
$kernel
->expects($this->any())
->method('handle')
->with($this->equalTo($request, 1))
;

return $kernel;
}

public function testExceptionInSubRequestsDoesNotMangleOutputBuffers()
{
$resolver = $this->getMock('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface');
Expand Down Expand Up @@ -173,14 +174,7 @@ public function testESIHeaderIsKeptInSubrequest()
$expectedSubRequest->server->set('HTTP_X_FORWARDED_FOR', '127.0.0.1');
}

$kernel = $this->getMock('Symfony\Component\HttpKernel\HttpKernelInterface');
$kernel
->expects($this->any())
->method('handle')
->with($expectedSubRequest)
;

$strategy = new InlineFragmentRenderer($kernel);
$strategy = new InlineFragmentRenderer($this->getKernelExpectingRequest($expectedSubRequest));

$request = Request::create('/');
$request->headers->set('Surrogate-Capability', 'abc="ESI/1.0"');
Expand Down

0 comments on commit 72d4583

Please sign in to comment.