Skip to content

Commit

Permalink
Merge branch '2.7' into 2.8
Browse files Browse the repository at this point in the history
* 2.7:
  [appveyor] fix ini matrix race conditions
  [Http*] Mock time() to fix transient tests
  [ci] Cache phpunit install
  [WebProfiler] [toolbar] Changed profiler toolbar color to comply with WCAG 2.0AA contrast standards

Conflicts:
	src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.css.twig
	src/Symfony/Component/HttpFoundation/Response.php
  • Loading branch information
nicolas-grekas committed Oct 13, 2015
2 parents 5958eb4 + 7e848fb commit 8a76fd9
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 58 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Expand Up @@ -7,6 +7,10 @@ addons:
- parallel
- language-pack-fr-base

cache:
directories:
- .phpunit

matrix:
include:
- php: hhvm
Expand Down
20 changes: 13 additions & 7 deletions appveyor.yml
Expand Up @@ -13,23 +13,24 @@ init:
- SET SYMFONY_DEPRECATIONS_HELPER=strict
- SET PHP=1
- SET ANSICON=121x90 (121x90)
- SET PHP_INI_MATRIX=php.ini-min php.ini-max
- SET SYMFONY_PHPUNIT_SKIPPED_TESTS=phpunit.skipped

install:
- IF EXIST c:\php (SET PHP=0) ELSE (mkdir c:\php)
- cd c:\php
- IF %PHP%==1 appveyor DownloadFile http://windows.php.net/downloads/releases/archives/php-5.3.11-nts-Win32-VC9-x86.zip
- IF %PHP%==1 7z x php-5.3.11-nts-Win32-VC9-x86.zip -y > 7z.log
- IF %PHP%==1 7z x php-5.3.11-nts-Win32-VC9-x86.zip -y >nul
- IF %PHP%==1 appveyor DownloadFile http://nebm.ist.utl.pt/~glopes/misc/intl_win/ICU-51.2-dlls.zip
- IF %PHP%==1 7z x ICU-51.2-dlls.zip -y > 7z.log
- IF %PHP%==1 7z x ICU-51.2-dlls.zip -y >nul
- IF %PHP%==1 del /Q *.zip
- IF %PHP%==1 cd ext
- IF %PHP%==1 appveyor DownloadFile http://nebm.ist.utl.pt/~glopes/misc/intl_win/php_intl-3.0.0-5.3-nts-vc9-x86.zip
- IF %PHP%==1 7z x php_intl-3.0.0-5.3-nts-vc9-x86.zip -y > 7z.log
- IF %PHP%==1 7z x php_intl-3.0.0-5.3-nts-vc9-x86.zip -y >nul
- IF %PHP%==1 appveyor DownloadFile http://windows.php.net/downloads/pecl/releases/apcu/4.0.7/php_apcu-4.0.7-5.3-nts-vc9-x86.zip
- IF %PHP%==1 7z x php_apcu-4.0.7-5.3-nts-vc9-x86.zip -y > 7z.log
- IF %PHP%==1 7z x php_apcu-4.0.7-5.3-nts-vc9-x86.zip -y >nul
- IF %PHP%==1 appveyor DownloadFile http://windows.php.net/downloads/pecl/releases/memcache/3.0.8/php_memcache-3.0.8-5.3-nts-vc9-x86.zip
- IF %PHP%==1 7z x php_memcache-3.0.8-5.3-nts-vc9-x86.zip -y > 7z.log
- IF %PHP%==1 7z x php_memcache-3.0.8-5.3-nts-vc9-x86.zip -y >nul
- IF %PHP%==1 del /Q *.zip
- IF %PHP%==1 cd ..
- IF %PHP%==1 echo @php %%~dp0composer.phar %%* > composer.bat
- IF %PHP%==1 copy /Y php.ini-development php.ini-min
Expand All @@ -55,4 +56,9 @@ install:

test_script:
- cd c:\projects\symfony
- php phpunit symfony --exclude-group benchmark,intl-data
- SET X=0
- copy /Y c:\php\php.ini-min c:\php\php.ini
- php phpunit symfony --exclude-group benchmark,intl-data || SET X=1
- copy /Y c:\php\php.ini-max c:\php\php.ini
- php phpunit symfony --exclude-group benchmark,intl-data || SET X=1
- exit %X%
27 changes: 6 additions & 21 deletions phpunit
Expand Up @@ -24,14 +24,14 @@ if (!file_exists($COMPOSER = __DIR__.'/composer.phar')) {
$PHP = ProcessUtils::escapeArgument($PHP);
$COMPOSER = $PHP.' '.ProcessUtils::escapeArgument($COMPOSER);

if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__FILE__) !== @file_get_contents("$PHPUNIT_DIR/.md5") || (isset($argv[1]) && 'install' === $argv[1])) {
if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__FILE__) !== @file_get_contents("$PHPUNIT_DIR/.md5")) {
// Build a standalone phpunit without symfony/yaml

$oldPwd = getcwd();
@mkdir($PHPUNIT_DIR);
chdir($PHPUNIT_DIR);
if (file_exists("phpunit-$PHPUNIT_VERSION")) {
passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? 'del /S /F /Q %s & rmdir %1$s >nul 2>&1': 'rm -rf %s', "phpunit-$PHPUNIT_VERSION"));
passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? '(del /S /F /Q %s & rmdir %1$s) >nul': 'rm -rf %s', "phpunit-$PHPUNIT_VERSION"));
}
if (extension_loaded('openssl') && ini_get('allow_url_fopen')) {
stream_copy_to_stream(fopen("https://github.com/sebastianbergmann/phpunit/archive/$PHPUNIT_VERSION.zip", 'rb'), fopen("$PHPUNIT_VERSION.zip", 'wb'));
Expand All @@ -58,7 +58,7 @@ EOPHP
);
chdir('..');
if (file_exists('../src/Symfony/Bridge/PhpUnit') && `git diff --name-only HEAD^ -- ../src/Symfony/Bridge/PhpUnit`) {
passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? 'del /S /F /Q %s & rmdir %1$s >nul 2>&1': 'rm -rf %s', str_replace('/', DIRECTORY_SEPARATOR, "phpunit-$PHPUNIT_VERSION/vendor/symfony/phpunit-bridge")));
passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? '(del /S /F /Q %s & rmdir %1$s) >nul': 'rm -rf %s', str_replace('/', DIRECTORY_SEPARATOR, "phpunit-$PHPUNIT_VERSION/vendor/symfony/phpunit-bridge")));
symlink(realpath('../src/Symfony/Bridge/PhpUnit'), "phpunit-$PHPUNIT_VERSION/vendor/symfony/phpunit-bridge");
}
file_put_contents('.md5', md5_file(__FILE__));
Expand All @@ -76,22 +76,10 @@ if (isset($argv[1]) && 'symfony' === $argv[1]) {
$cmd[0] = sprintf('%s %s --colors=always', $PHP, ProcessUtils::escapeArgument("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit"));
$cmd = str_replace('%', '%%', implode(' ', $cmd)).' %1$s';

$phpIniMatrix = isset($_SERVER['PHP_INI_MATRIX']) ? explode(' ', $_SERVER['PHP_INI_MATRIX']) : array();
if ($phpIniMatrix) {
if ('\\' !== DIRECTORY_SEPARATOR) {
echo "Error: PHP_INI_MATRIX is a Windows-only feature.\n";
exit(1);
}

$phpDir = ProcessUtils::escapeArgument(dirname(`where.exe php`));

$newCmd = 'cmd /v:on /d /c "(SET X=0';
foreach ($phpIniMatrix as $iniFile) {
$newCmd .= " & copy /Y $phpDir\\$iniFile $phpDir\\php.ini & echo. & echo Running tests with $iniFile: & ($cmd || SET X=1)";
}
$cmd = $newCmd .= ' & exit !X!)%2$s"';
if ('\\' === DIRECTORY_SEPARATOR) {
$cmd = 'cmd /v:on /d /c "('.$cmd.')%2$s"';
} else {
$cmd .= ' %2$s';
$cmd .= '%2$s';
}

if (isset($argv[1]) && 'symfony' === $argv[1]) {
Expand Down Expand Up @@ -168,9 +156,6 @@ if (isset($argv[1]) && 'symfony' === $argv[1]) {
}
unlink($file);
}
if ($skippedTests) {
@unlink("$component/$skippedTests");
}

if ($procStatus) {
$exit = 1;
Expand Down
Expand Up @@ -272,7 +272,6 @@ public function testSubmitDifferentPattern()
$this->assertDateTimeEquals($dateTime, $form->getData());
}

// Bug fix
public function testInitializeWithDateTime()
{
// Throws an exception if "data_class" option is not explicitly set
Expand Down
Expand Up @@ -715,7 +715,6 @@ public function testPassWidgetToView()
$this->assertSame('single_text', $view->vars['widget']);
}

// Bug fix
public function testInitializeWithDateTime()
{
// Throws an exception if "data_class" option is not explicitly set
Expand Down
Expand Up @@ -477,7 +477,6 @@ public function testIsPartiallyFilledReturnsTrueIfChoiceAndSecondsEmpty()
$this->assertTrue($form->isPartiallyFilled());
}

// Bug fix
public function testInitializeWithDateTime()
{
// Throws an exception if "data_class" option is not explicitly set
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/HttpFoundation/Response.php
Expand Up @@ -325,7 +325,7 @@ public function sendHeaders()
}

if (!$this->headers->has('Date')) {
$this->setDate(new \DateTime());
$this->setDate(\DateTime::createFromFormat('U', time()));
}

// status
Expand Down Expand Up @@ -608,7 +608,7 @@ public function mustRevalidate()
public function getDate()
{
if (!$this->headers->has('Date')) {
$this->setDate(new \DateTime());
$this->setDate(\DateTime::createFromFormat('U', time()));
}

return $this->headers->getDate('Date');
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpFoundation/Tests/CookieTest.php
Expand Up @@ -95,7 +95,7 @@ public function testGetExpiresTimeWithStringValue()
$cookie = new Cookie('foo', 'bar', $value);
$expire = strtotime($value);

$this->assertEquals($expire, $cookie->getExpiresTime(), '->getExpiresTime() returns the expire date');
$this->assertEquals($expire, $cookie->getExpiresTime(), '->getExpiresTime() returns the expire date', 1);
}

public function testGetDomain()
Expand Down
37 changes: 20 additions & 17 deletions src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php
Expand Up @@ -14,6 +14,9 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

/**
* @group time-sensitive
*/
class ResponseTest extends ResponseTestCase
{
public function testCreate()
Expand Down Expand Up @@ -259,16 +262,18 @@ public function testGetDate()
{
$oneHourAgo = $this->createDateTimeOneHourAgo();
$response = new Response('', 200, array('Date' => $oneHourAgo->format(DATE_RFC2822)));
$this->assertEquals(0, $oneHourAgo->diff($response->getDate())->format('%s'), '->getDate() returns the Date header if present');
$date = $response->getDate();
$this->assertEquals($oneHourAgo->getTimestamp(), $date->getTimestamp(), '->getDate() returns the Date header if present');

$response = new Response();
$date = $response->getDate();
$this->assertLessThan(1, $date->diff(new \DateTime(), true)->format('%s'), '->getDate() returns the current Date if no Date header present');
$this->assertEquals(time(), $date->getTimestamp(), '->getDate() returns the current Date if no Date header present');

$response = new Response('', 200, array('Date' => $this->createDateTimeOneHourAgo()->format(DATE_RFC2822)));
$now = $this->createDateTimeNow();
$response->headers->set('Date', $now->format(DATE_RFC2822));
$this->assertLessThanOrEqual(1, $now->diff($response->getDate())->format('%s'), '->getDate() returns the date when the header has been modified');
$date = $response->getDate();
$this->assertEquals($now->getTimestamp(), $date->getTimestamp(), '->getDate() returns the date when the header has been modified');

$response = new Response('', 200);
$response->headers->remove('Date');
Expand All @@ -288,7 +293,7 @@ public function testGetMaxAge()
$response = new Response();
$response->headers->set('Cache-Control', 'must-revalidate');
$response->headers->set('Expires', $this->createDateTimeOneHourLater()->format(DATE_RFC2822));
$this->assertLessThanOrEqual(1, $response->getMaxAge() - 3600, '->getMaxAge() falls back to Expires when no max-age or s-maxage directive present');
$this->assertEquals(3600, $response->getMaxAge(), '->getMaxAge() falls back to Expires when no max-age or s-maxage directive present');

$response = new Response();
$response->headers->set('Cache-Control', 'must-revalidate');
Expand Down Expand Up @@ -359,7 +364,7 @@ public function testGetTtl()

$response = new Response();
$response->headers->set('Expires', $this->createDateTimeOneHourLater()->format(DATE_RFC2822));
$this->assertLessThanOrEqual(1, 3600 - $response->getTtl(), '->getTtl() uses the Expires header when no max-age is present');
$this->assertEquals(3600, $response->getTtl(), '->getTtl() uses the Expires header when no max-age is present');

$response = new Response();
$response->headers->set('Expires', $this->createDateTimeOneHourAgo()->format(DATE_RFC2822));
Expand All @@ -372,7 +377,7 @@ public function testGetTtl()

$response = new Response();
$response->headers->set('Cache-Control', 'max-age=60');
$this->assertLessThan(1, 60 - $response->getTtl(), '->getTtl() uses Cache-Control max-age when present');
$this->assertEquals(60, $response->getTtl(), '->getTtl() uses Cache-Control max-age when present');
}

public function testSetClientTtl()
Expand Down Expand Up @@ -572,7 +577,7 @@ public function testSetCache()
$response->setCache($options);
$this->assertEquals($response->getEtag(), '"whatever"');

$now = new \DateTime();
$now = $this->createDateTimeNow();
$options = array('last_modified' => $now);
$response->setCache($options);
$this->assertEquals($response->getLastModified()->getTimestamp(), $now->getTimestamp());
Expand Down Expand Up @@ -631,7 +636,7 @@ public function testSetExpires()

$this->assertNull($response->getExpires(), '->setExpires() remove the header when passed null');

$now = new \DateTime();
$now = $this->createDateTimeNow();
$response->setExpires($now);

$this->assertEquals($response->getExpires()->getTimestamp(), $now->getTimestamp());
Expand All @@ -640,7 +645,7 @@ public function testSetExpires()
public function testSetLastModified()
{
$response = new Response();
$response->setLastModified(new \DateTime());
$response->setLastModified($this->createDateTimeNow());
$this->assertNotNull($response->getLastModified());

$response->setLastModified(null);
Expand Down Expand Up @@ -825,7 +830,7 @@ public function testSettersAreChainable()
'setCharset' => 'UTF-8',
'setPublic' => null,
'setPrivate' => null,
'setDate' => new \DateTime(),
'setDate' => $this->createDateTimeNow(),
'expire' => null,
'setMaxAge' => 1,
'setSharedMaxAge' => 1,
Expand Down Expand Up @@ -858,21 +863,19 @@ public function invalidContentProvider()

protected function createDateTimeOneHourAgo()
{
$date = new \DateTime();

return $date->sub(new \DateInterval('PT1H'));
return $this->createDateTimeNow()->sub(new \DateInterval('PT1H'));
}

protected function createDateTimeOneHourLater()
{
$date = new \DateTime();

return $date->add(new \DateInterval('PT1H'));
return $this->createDateTimeNow()->add(new \DateInterval('PT1H'));
}

protected function createDateTimeNow()
{
return new \DateTime();
$date = new \DateTime();

return $date->setTimestamp(time());
}

protected function provideResponse()
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php
Expand Up @@ -212,7 +212,7 @@ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQ

$this->restoreResponseBody($request, $response);

$response->setDate(new \DateTime(null, new \DateTimeZone('UTC')));
$response->setDate(\DateTime::createFromFormat('U', time(), new \DateTimeZone('UTC')));

if (HttpKernelInterface::MASTER_REQUEST === $type && $this->options['debug']) {
$response->headers->set('X-Symfony-Cache', $this->getLog());
Expand Down
17 changes: 11 additions & 6 deletions src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php
Expand Up @@ -15,6 +15,9 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

/**
* @group time-sensitive
*/
class HttpCacheTest extends HttpCacheTestCase
{
public function testTerminateDelegatesTerminationOnlyForTerminableInterface()
Expand Down Expand Up @@ -125,7 +128,7 @@ public function testDoesNotCacheRequestsWithACookieHeader()

public function testRespondsWith304WhenIfModifiedSinceMatchesLastModified()
{
$time = new \DateTime();
$time = \DateTime::createFromFormat('U', time());

$this->setNextResponse(200, array('Cache-Control' => 'public', 'Last-Modified' => $time->format(DATE_RFC2822), 'Content-Type' => 'text/plain'), 'Hello World');
$this->request('GET', '/', array('HTTP_IF_MODIFIED_SINCE' => $time->format(DATE_RFC2822)));
Expand Down Expand Up @@ -154,7 +157,7 @@ public function testRespondsWith304WhenIfNoneMatchMatchesETag()

public function testRespondsWith304OnlyIfIfNoneMatchAndIfModifiedSinceBothMatch()
{
$time = new \DateTime();
$time = \DateTime::createFromFormat('U', time());

$this->setNextResponse(200, array(), '', function ($request, $response) use ($time) {
$response->setStatusCode(200);
Expand Down Expand Up @@ -593,7 +596,7 @@ public function testAssignsDefaultTtlWhenResponseHasNoFreshnessInformationAndAft
$this->assertTraceContains('miss');
$this->assertTraceContains('store');
$this->assertEquals('Hello World', $this->response->getContent());
$this->assertRegExp('/s-maxage=(?:2|3)/', $this->response->headers->get('Cache-Control'));
$this->assertRegExp('/s-maxage=2/', $this->response->headers->get('Cache-Control'));

$this->request('GET', '/');
$this->assertHttpKernelIsNotCalled();
Expand All @@ -607,7 +610,8 @@ public function testAssignsDefaultTtlWhenResponseHasNoFreshnessInformationAndAft
$values = $this->getMetaStorageValues();
$this->assertCount(1, $values);
$tmp = unserialize($values[0]);
$tmp[0][1]['date'] = \DateTime::createFromFormat('U', time() - 5)->format(DATE_RFC2822);
$time = \DateTime::createFromFormat('U', time() - 5);
$tmp[0][1]['date'] = $time->format(DATE_RFC2822);
$r = new \ReflectionObject($this->store);
$m = $r->getMethod('save');
$m->setAccessible(true);
Expand Down Expand Up @@ -656,7 +660,8 @@ public function testAssignsDefaultTtlWhenResponseHasNoFreshnessInformationAndAft
$values = $this->getMetaStorageValues();
$this->assertCount(1, $values);
$tmp = unserialize($values[0]);
$tmp[0][1]['date'] = \DateTime::createFromFormat('U', time() - 5)->format(DATE_RFC2822);
$time = \DateTime::createFromFormat('U', time() - 5);
$tmp[0][1]['date'] = $time->format(DATE_RFC2822);
$r = new \ReflectionObject($this->store);
$m = $r->getMethod('save');
$m->setAccessible(true);
Expand Down Expand Up @@ -1197,7 +1202,7 @@ public function testXForwarderForHeaderForPassRequests()

public function testEsiCacheRemoveValidationHeadersIfEmbeddedResponses()
{
$time = new \DateTime();
$time = \DateTime::createFromFormat('U', time());

$responses = array(
array(
Expand Down
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\HttpKernel\HttpCache\HttpCache;
use Symfony\Component\HttpKernel\HttpCache\Store;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Bridge\PhpUnit\ClockMock;

class HttpCacheTestCase extends \PHPUnit_Framework_TestCase
{
Expand All @@ -32,6 +33,9 @@ class HttpCacheTestCase extends \PHPUnit_Framework_TestCase

protected function setUp()
{
if (class_exists('Symfony\Bridge\PhpUnit\ClockMock')) {
ClockMock::register('Symfony\Component\HttpFoundation\Request');
}
$this->kernel = null;

$this->cache = null;
Expand Down

0 comments on commit 8a76fd9

Please sign in to comment.