8000 Merge branch '2.7' into 2.8 · symfony/symfony@8a76fd9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8a76fd9

Browse files
Merge branch '2.7' into 2.8
* 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
2 parents 5958eb4 + 7e848fb commit 8a76fd9

File tree

12 files changed

+62
-58
lines changed

12 files changed

+62
-58
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ addons:
77
- parallel
88
- language-pack-fr-base
99

10+
cache:
11+
directories:
12+
- .phpunit
13+
1014
matrix:
1115
include:
1216
- php: hhvm

appveyor.yml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,24 @@ init:
1313
- SET SYMFONY_DEPRECATIONS_HELPER=strict
1414
- SET PHP=1
1515
- SET ANSICON=121x90 (121x90)
16-
- SET PHP_INI_MATRIX=php.ini-min php.ini-max
1716
- SET SYMFONY_PHPUNIT_SKIPPED_TESTS=phpunit.skipped
1817

1918
install:
2019
- IF EXIST c:\php (SET PHP=0) ELSE (mkdir c:\php)
2120
- cd c:\php
2221
- IF %PHP%==1 appveyor DownloadFile http://windows.php.net/downloads/releases/archives/php-5.3.11-nts-Win32-VC9-x86.zip
23-
- IF %PHP%==1 7z x php-5.3.11-nts-Win32-VC9-x86.zip -y > 7z.log
22+
- IF %PHP%==1 7z x php-5.3.11-nts-Win32-VC9-x86.zip -y >nul
2423
- IF %PHP%==1 appveyor DownloadFile http://nebm.ist.utl.pt/~glopes/misc/intl_win/ICU-51.2-dlls.zip
25-
- IF %PHP%==1 7z x ICU-51.2-dlls.zip -y > 7z.log
24+
- IF %PHP%==1 7z x ICU-51.2-dlls.zip -y >nul
25+
- IF %PHP%==1 del /Q *.zip
2626
- IF %PHP%==1 cd ext
2727
- 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
28-
- IF %PHP%==1 7z x php_intl-3.0.0-5.3-nts-vc9-x86.zip -y > 7z.log
28+
- IF %PHP%==1 7z x php_intl-3.0.0-5.3-nts-vc9-x86.zip -y >nul
2929
- 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
30-
- IF %PHP%==1 7z x php_apcu-4.0.7-5.3-nts-vc9-x86.zip -y > 7z.log
30+
- IF %PHP%==1 7z x php_apcu-4.0.7-5.3-nts-vc9-x86.zip -y >nul
3131
- 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
32-
- IF %PHP%==1 7z x php_memcache-3.0.8-5.3-nts-vc9-x86.zip -y > 7z.log
32+
- IF %PHP%==1 7z x php_memcache-3.0.8-5.3-nts-vc9-x86.zip -y >nul
33+
- IF %PHP%==1 del /Q *.zip
3334
- IF %PHP%==1 cd ..
3435
- IF %PHP%==1 echo @php %%~dp0composer.phar %%* > composer.bat
3536
- IF %PHP%==1 copy /Y php.ini-development php.ini-min
@@ -55,4 +56,9 @@ install:
5556

5657
test_script:
5758
- cd c:\projects\symfony
58-
- php phpunit symfony --exclude-group benchmark,intl-data
59+
- SET X=0
60+
- copy /Y c:\php\php.ini-min c:\php\php.ini
61+
- php phpunit symfony --exclude-group benchmark,intl-data || SET X=1
62+
- copy /Y c:\php\php.ini-max c:\php\php.ini
63+
- php phpunit symfony --exclude-group benchmark,intl-data || SET X=1
64+
- exit %X%

phpunit

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ if (!file_exists($COMPOSER = __DIR__.'/composer.phar')) {
2424
$PHP = ProcessUtils::escapeArgument($PHP);
2525
$COMPOSER = $PHP.' '.ProcessUtils::escapeArgument($COMPOSER);
2626

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

3030
$oldPwd = getcwd();
3131
@mkdir($PHPUNIT_DIR);
3232
chdir($PHPUNIT_DIR);
3333
if (file_exists("phpunit-$PHPUNIT_VERSION")) {
34-
passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? 'del /S /F /Q %s & rmdir %1$s >nul 2>&1': 'rm -rf %s', "phpunit-$PHPUNIT_VERSION"));
34+
passthru(sprintf('\\' === DIRECTORY_SEPARATOR ? '(del /S /F /Q %s & rmdir %1$s) >nul': 'rm -rf %s', "phpunit-$PHPUNIT_VERSION"));
3535
}
3636
if (extension_loaded('openssl') && ini_get('allow_url_fopen')) {
3737
stream_copy_to_stream(fopen("https://github.com/sebastianbergmann/phpunit/archive/$PHPUNIT_VERSION.zip", 'rb'), fopen("$PHPUNIT_VERSION.zip", 'wb'));
@@ -58,7 +58,7 @@ EOPHP
5858
);
5959
chdir('..');
6060
if (file_exists('../src/Symfony/Bridge/PhpUnit') && `git diff --name-only HEAD^ -- ../src/Symfony/Bridge/PhpUnit`) {
61-
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")));
61+
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")));
6262
symlink(realpath('../src/Symfony/Bridge/PhpUnit'), "phpunit-$PHPUNIT_VERSION/vendor/symfony/phpunit-bridge");
6363
}
6464
file_put_contents('.md5', md5_file(__FILE__));
@@ -76,22 +76,10 @@ if (isset($argv[1]) && 'symfony' === $argv[1]) {
7676
$cmd[0] = sprintf('%s %s --colors=always', $PHP, ProcessUtils::escapeArgument("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit"));
7777
$cmd = str_replace('%', '%%', implode(' ', $cmd)).' %1$s';
7878

79-
$phpIniMatrix = isset($_SERVER['PHP_INI_MATRIX']) ? explode(' ', $_SERVER['PHP_INI_MATRIX']) : array();
80-
if ($phpIniMatrix) {
81-
if ('\\' !== DIRECTORY_SEPARATOR) {
82-
echo "Error: PHP_INI_MATRIX is a Windows-only feature.\n";
83-
exit(1);
84-
}
85-
86-
$phpDir = ProcessUtils::escapeArgument(dirname(`where.exe php`));
87-
88-
$newCmd = 'cmd /v:on /d /c "(SET X=0';
89-
foreach ($phpIniMatrix as $iniFile) {
90-
$newCmd .= " & copy /Y $phpDir\\$iniFile $phpDir\\php.ini & echo. & echo Running tests with $iniFile: & ($cmd || SET X=1)";
91-
}
92-
$cmd = $newCmd .= ' & exit !X!)%2$s"';
79+
if ('\\' === DIRECTORY_SEPARATOR) {
80+
$cmd = 'cmd /v:on /d /c "('.$cmd.')%2$s"';
9381
} else {
94-
$cmd .= ' %2$s';
82+
$cmd .= '%2$s';
9583
}
9684

9785
if (isset($argv[1]) && 'symfony' === $argv[1]) {
@@ -168,9 +156,6 @@ if (isset($argv[1]) && 'symfony' === $argv[1]) {
168156
}
169157
unlink($file);
170158
}
171-
if ($skippedTests) {
172-
@unlink("$component/$skippedTests");
173-
}
174159

175160
if ($procStatus) {
176161
$exit = 1;

src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTimeTypeTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ public function testSubmitDifferentPattern()
272272
$this->assertDateTimeEquals($dateTime, $form->getData());
273273
}
274274

275-
// Bug fix
276275
public function testInitializeWithDateTime()
277276
{
278277
// Throws an exception if "data_class" option is not explicitly set

src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,6 @@ public function testPassWidgetToView()
715715
$this->assertSame('single_text', $view->vars['widget']);
716716
}
717717

718-
// Bug fix
719718
public function testInitializeWithDateTime()
720719
{
721720
// Throws an exception if "data_class" option is not explicitly set

src/Symfony/Component/Form/Tests/Extension/Core/Type/TimeTypeTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,6 @@ public function testIsPartiallyFilledReturnsTrueIfChoiceAndSecondsEmpty()
477477
$this->assertTrue($form->isPartiallyFilled());
478478
}
479479

480-
// Bug fix
481480
public function testInitializeWithDateTime()
482481
{
483482
// Throws an exception if "data_class" option is not explicitly set

src/Symfony/Component/HttpFoundation/Response.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ public function sendHeaders()
325325
}
326326

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

331331
// status
@@ -608,7 +608,7 @@ public function mustRevalidate()
608608
public function getDate()
609609
{
610610
if (!$this->headers->has('Date')) {
611-
$this->setDate(new \DateTime());
611+
$this->setDate(\DateTime::createFromFormat('U', time()));
612612
}
613613

614614
return $this->headers->getDate('Date');

src/Symfony/Component/HttpFoundation/Tests/CookieTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function testGetExpiresTimeWithStringValue()
9595
$cookie = new Cookie('foo', 'bar', $value);
9696
$expire = strtotime($value);
9797

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

101101
public function testGetDomain()

src/Symfony/Component/HttpFoundation/Tests/ResponseTest.php

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
use Symfony\Component\HttpFoundation\Request;
1515
use Symfony\Component\HttpFoundation\Response;
1616

17+
/**
18+
* @group time-sensitive
19+
*/
1720
class ResponseTest extends ResponseTestCase
1821
{
1922
public function testCreate()
@@ -259,16 +262,18 @@ public function testGetDate()
259262
{
260263
$oneHourAgo = $this->createDateTimeOneHourAgo();
261264
$response = new Response('', 200, array('Date' => $oneHourAgo->format(DATE_RFC2822)));
262-
$this->assertEquals(0, $oneHourAgo->diff($response->getDate())->format('%s'), '->getDate() returns the Date header if present');
265+
$date = $response->getDate();
266+
$this->assertEquals($oneHourAgo->getTimestamp(), $date->getTimestamp(), '->getDate() returns the Date header if present');
263267

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

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

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

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

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

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

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

378383
public function testSetClientTtl()
@@ -572,7 +577,7 @@ public function testSetCache()
572577
$response->setCache($options);
573578
$this->assertEquals($response->getEtag(), '"whatever"');
574579

575-
$now = new \DateTime();
580+
$now = $this->createDateTimeNow();
576581
$options = array('last_modified' => $now);
577582
$response->setCache($options);
578583
$this->assertEquals($response->getLastModified()->getTimestamp(), $now->getTimestamp());
@@ -631,7 +636,7 @@ public function testSetExpires()
631636

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

634-
$now = new \DateTime();
639+
$now = $this->createDateTimeNow();
635640
$response->setExpires($now);
636641

637642
$this->assertEquals($response->getExpires()->getTimestamp(), $now->getTimestamp());
@@ -640,7 +645,7 @@ public function testSetExpires()
640645
public function testSetLastModified()
641646
{
642647
$response = new Response();
643-
$response->setLastModified(new \DateTime());
648+
$response->setLastModified($this->createDateTimeNow());
644649
$this->assertNotNull($response->getLastModified());
645650

646651
$response->setLastModified(null);
@@ -825,7 +830,7 @@ public function testSettersAreChainable()
825830
'setCharset' => 'UTF-8',
826831
'setPublic' => null,
827832
'setPrivate' => null,
828-
'setDate' => new \DateTime(),
833+
'setDate' => $this->createDateTimeNow(),
829834
'expire' => null,
830835
'setMaxAge' => 1,
831836
'setSharedMaxAge' => 1,
@@ -858,21 +863,19 @@ public function invalidContentProvider()
858863

859864
protected function createDateTimeOneHourAgo()
860865
{
861-
$date = new \DateTime();
862-
863-
return $date->sub(new \DateInterval('PT1H'));
866+
return $this->createDateTimeNow()->sub(new \DateInterval('PT1H'));
864867
}
865868

866869
protected function createDateTimeOneHourLater()
867870
{
868-
$date = new \DateTime();
869-
870-
return $date->add(new \DateInterval('PT1H'));
871+
return $this->createDateTimeNow()->add(new \DateInterval('PT1H'));
871872
}
872873

873874
protected function createDateTimeNow()
874875
{
875-
return new \DateTime();
876+
$date = new \DateTime();
877+
878+
return $date->setTimestamp(time());
876879
}
877880

878881
protected function provideResponse()

src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQ
212212

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

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

217217
if (HttpKernelInterface::MASTER_REQUEST === $type && $this->options['debug']) {
218218
$response->headers->set('X-Symfony-Cache', $this->getLog());

src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
use Symfony\Component\HttpFoundation\Request;
1616
use Symfony\Component\HttpFoundation\Response;
1717

18+
/**
19+
* @group time-sensitive
20+
*/
1821
class HttpCacheTest extends HttpCacheTestCase
1922
{
2023
public function testTerminateDelegatesTerminationOnlyForTerminableInterface()
@@ -125,7 +128,7 @@ public function testDoesNotCacheRequestsWithACookieHeader()
125128

126129
public function testRespondsWith304WhenIfModifiedSinceMatchesLastModified()
127130
{
128-
$time = new \DateTime();
131+
$time = \DateTime::createFromFormat('U', time());
129132

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

155158
public function testRespondsWith304OnlyIfIfNoneMatchAndIfModifiedSinceBothMatch()
156159
{
157-
$time = new \DateTime();
160+
$time = \DateTime::createFromFormat('U', time());
158161

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

598601
$this->request('GET', '/');
599602
$this->assertHttpKernelIsNotCalled();
@@ -607,7 +610,8 @@ public function testAssignsDefaultTtlWhenResponseHasNoFreshnessInformationAndAft
607610
$values = $this->getMetaStorageValues();
608611
$this->assertCount(1, $values);
609612
$tmp = unserialize($values[0]);
610-
$tmp[0][1]['date'] = \DateTime::createFromFormat('U', time() - 5)->format(DATE_RFC2822);
613+
$time = \DateTime::createFromFormat('U', time() - 5);
614+
$tmp[0][1]['date'] = $time->format(DATE_RFC2822);
611615
$r = new \ReflectionObject($this->store);
612616
$m = $r->getMethod('save');
613617
$m->setAccessible(true);
@@ -656,7 +660,8 @@ public function testAssignsDefaultTtlWhenResponseHasNoFreshnessInformationAndAft
656660
$values = $this->getMetaStorageValues();
657661
$this->assertCount(1, $values);
658662
$tmp = unserialize($values[0]);
659-
$tmp[0][1]['date'] = \DateTime::createFromFormat('U', time() - 5)->format(DATE_RFC2822);
663+
$time = \DateTime::createFromFormat('U', time() - 5);
664+
$tmp[0][1]['date'] = $time->format(DATE_RFC2822);
660665
$r = new \ReflectionObject($this->store);
661666
$m = $r->getMethod('save');
662667
$m->setAccessible(true);
@@ -1197,7 +1202,7 @@ public function testXForwarderForHeaderForPassRequests()
11971202

11981203
public function testEsiCacheRemoveValidationHeadersIfEmbeddedResponses()
11991204
{
1200-
$time = new \DateTime();
1205+
$time = \DateTime::createFromFormat('U', time());
12011206

12021207
$responses = array(
12031208
array(

src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTestCase.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\HttpKernel\HttpCache\HttpCache;
1717
use Symfony\Component\HttpKernel\HttpCache\Store;
1818
use Symfony\Component\HttpKernel\HttpKernelInterface;
19+
use Symfony\Bridge\PhpUnit\ClockMock;
1920

2021
class HttpCacheTestCase extends \PHPUnit_Framework_TestCase
2122
{
@@ -32,6 +33,9 @@ class HttpCacheTestCase extends \PHPUnit_Framework_TestCase
3233

3334
protected function setUp()
3435
{
36+
if (class_exists('Symfony\Bridge\PhpUnit\ClockMock')) {
37+
ClockMock::register('Symfony\Component\HttpFoundation\Request');
38+
}
3539
$this->kernel = null;
3640

3741
$this->cache = null;

0 commit comments

Comments
 (0)
0