Skip to content

Instantly share code, notes, and snippets.

@nojimage
Created October 29, 2013 10:18
Show Gist options
  • Save nojimage/7212052 to your computer and use it in GitHub Desktop.
Save nojimage/7212052 to your computer and use it in GitHub Desktop.
timecop拡張を入れていると、WebTestCase経由のテストでResponse::setLastModifiedが使えない問題の対処 ;)
<?php
// ...
if (!extension_loaded('timecop')) {
$response = $app->sendFile($file, 200, $headers);
} else {
// timecop hack
$response = new Symfony\Component\HttpFoundation\BinaryFileResponse($file, 200, $headers, false, null, false, false);
$date = \DateTime::createFromFormat('U', $response->getFile()->getMTime());
$date->setTimezone(new \DateTimeZone('UTC'));
$response->headers->set('Last-Modified', $date->format('D, d M Y H:i:s').' GMT');
}
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment