8000 Merge branch '3.3' into 3.4 · symfony/symfony@2c18da7 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2c18da7

Browse files
Merge branch '3.3' into 3.4
* 3.3: [BrowserKit] Handle deprecations triggered in insulated requests [Bridge\PhpUnit] Handle deprecations triggered in separate processes [Validator] added magic method __isset() to File Constraint class [DI] Fix possible incorrect php-code when dumped strings contains newlines [Translation] minor: remove unused variable in test never match invalid IP addresses
2 parents ac6d605 + 17b48ed commit 2c18da7

File tree

12 files changed

+140
-17
lines changed

12 files changed

+140
-17
lines changed

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,20 @@ public static function register($mode = 0)
238238
}
239239
}
240240

241+
public static function collectDeprecations($outputFile)
242+
{
243+
$deprecations = array();
244+
$previousErrorHandler = set_error_handler(function ($type, $msg, $file, $line, $context = array()) use (&$deprecations, &$previousErrorHandler) {
245+
if (E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) {
246+
return $previousErrorHandler ? $previousErrorHandler($type, $msg, $file, $line, $context) : false;
247+
}
248+
$deprecations[] = array(error_reporting(), $msg);
249+
});
250+
register_shutdown_function(function () use ($outputFile, &$deprecations) {
251+
file_put_contents($outputFile, serialize($deprecations));
252+
});
253+
}
254+
241255
private static function hasColorSupport()
242256
{
243257
if ('\\' === DIRECTORY_SEPARATOR) {

src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class SymfonyTestsListenerTrait
3939
private $testsWithWarnings;
4040
private $reportUselessTests;
4141
private $error;
42+
private $runsInSeparateProcess = false;
4243

4344
/**
4445
* @param array $mockedNamespaces List of namespaces, indexed by mocked features (time-sensitive or dns-sensitive)
@@ -183,6 +184,12 @@ public function startTest($test)
183184
$this->reportUselessTests = $test->getTestResultObject()->isStrictAboutTestsThatDoNotTestAnything();
184185
}
185186

187+
// This event is triggered before the test is re-run in isolation
188+
if ($this->willBeIsolated($test)) {
189+
$this->runsInSeparateProcess = tempnam(sys_get_temp_dir(), 'deprec');
190+
putenv('SYMFONY_DEPRECATIONS_SERIALIZE='.$this->runsInSeparateProcess);
191+
}
192+
186193
if (class_exists('PHPUnit_Util_Blacklist', false)) {
187194
$Test = 'PHPUnit_Util_Test';
188195
$AssertionFailedError = 'PHPUnit_Framework_AssertionFailedError';
@@ -192,12 +199,14 @@ public function startTest($test)
192199
}
193200
$groups = $Test::getGroups(get_class($test), $test->getName(false));
194201

195-
if (in_array('time-sensitive', $groups, true)) {
196-
ClockMock::register(get_class($test));
197-
ClockMock::withClockMock(true);
198-
}
199-
if (in_array('dns-sensitive', $groups, true)) {
200-
DnsMock::register(get_class($test));
202+
if (!$this->runsInSeparateProcess) {
203+
if (in_array('time-sensitive', $groups, true)) {
204+
ClockMock::register(get_class($test));
205+
ClockMock::withClockMock(true);
206+
}
207+
if (in_array('dns-sensitive', $groups, true)) {
208+
DnsMock::register(get_class($test));
209+
}
201210
}
202211

203212
$annotations = $Test::parseTestMethodAnnotations(get_class($test), $test->getName(false));
@@ -245,15 +254,20 @@ public function endTest($test, $time)
245254
$this->reportUselessTests = null;
246255
}
247256

248-
$errored = false;
257+
if ($errored = null !== $this->error) {
258+
$test->getTestResultObject()->addError($test, $this->error, 0);
259+
$this->error = null;
260+
}
249261

250-
if (null !== $this->error) {
251-
if ($BaseTestRunner::STATUS_PASSED === $test->getStatus()) {
252-
$test->getTestResultObject()->addError($test, $this->error, 0);
253-
$errored = true;
262+
if ($this->runsInSeparateProcess) {
263+
foreach (unserialize(file_get_contents($this->runsInSeparateProcess)) as $deprecation) {
264+
if ($deprecation[0]) {
265+
trigger_error($deprecation[1], E_USER_DEPRECATED);
266+
} else {
267+
@trigger_error($deprecation[1], E_USER_DEPRECATED);
268+
}
254269
}
255-
256-
$this->error = null;
270+
$this->runsInSeparateProcess = false;
257271
}
258272

259273
if ($this->expectedDeprecations) {
@@ -277,7 +291,7 @@ public function endTest($test, $time)
277291
$this->expectedDeprecations = $this->gatheredDeprecations = array();
278292
$this->previousErrorHandler = null;
279293
}
280-
if (-2 < $this->state && ($test instanceof \PHPUnit_Framework_TestCase || $test instanceof TestCase)) {
294+
if (!$this->runsInSeparateProcess && -2 < $this->state && ($test instanceof \PHPUnit_Framework_TestCase || $test instanceof TestCase)) {
281295
if (in_array('time-sensitive', $groups, true)) {
282296
ClockMock::withClockMock(false);
283297
}
@@ -315,4 +329,21 @@ public function handleError($type, $msg, $file, $line, $context = array())
315329
}
316330
$this->gatheredDeprecations[] = $msg;
317331
}
332+
333+
/**
334+
* @param Test $test
335+
*
336+
* @return bool
337+
*/
338+
private function willBeIsolated($test)
339+
{
340+
if ($test->isInIsolation()) {
341+
return false;
342+
}
343+
344+
$r = new \ReflectionProperty($test, 'runTestInSeparateProcess');
345+
$r->setAccessible(true);
346+
347+
return $r->getValue($test);
348+
}
318349
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Symfony\Bridge\PhpUnit\Tests;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
/**
8+
* Don't remove this test case, it tests the legacy group.
9+
*
10+
* @group legacy
11+
*
12+
* @runTestsInSeparateProcesses
13+
*/
14+
class ProcessIsolationTest extends TestCase
15+
{
16+
/**
17+
* @expectedDeprecation Test abc
18+
*/
19+
public function testIsolation()
20+
{
21+
@trigger_error('Test abc', E_USER_DEPRECATED);
22+
}
23+
}

src/Symfony/Bridge/PhpUnit/bootstrap.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
// Detect if we're loaded by an actual run of phpunit
1616
if (!defined('PHPUNIT_COMPOSER_INSTALL') && !class_exists('PHPUnit_TextUI_Command', false) && !class_exists('PHPUnit\TextUI\Command', false)) {
17+
if ($ser = getenv('SYMFONY_DEPRECATIONS_SERIALIZE')) {
18+
DeprecationErrorHandler::collectDeprecations($ser);
19+
}
20+
1721
return;
1822
}
1923

src/Symfony/Component/BrowserKit/Client.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,23 @@ public function request($method, $uri, array $parameters = array(), array $files
346346
*/
347347
protected function doRequestInProcess($request)
348348
{
349+
$deprecationsFile = tempnam(sys_get_temp_dir(), 'deprec');
350+
putenv('SYMFONY_DEPRECATIONS_SERIALIZE='.$deprecationsFile);
349351
$process = new PhpProcess($this->getScript($request), null, null);
350352
$process->run();
351353

354+
if (file_exists($deprecationsFile)) {
355+
$deprecations = file_get_contents($deprecationsFile);
356+
unlink($deprecationsFile);
357+
foreach ($deprecations ? unserialize($deprecations) : array() as $deprecation) {
358+
if ($deprecation[0]) {
359+
trigger_error($deprecation[1], E_USER_DEPRECATED);
360+
} else {
361+
@trigger_error($deprecation[1], E_USER_DEPRECATED);
362+
}
363+
}
364+
}
365+
352366
if (!$process->isSuccessful() || !preg_match('/^O\:\d+\:/', $process->getOutput())) {
353367
throw new \RuntimeException(sprintf('OUTPUT: %s ERROR OUTPUT: %s', $process->getOutput(), $process->getErrorOutput()));
354368
}

src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1917,7 +1917,13 @@ private function export($value)
19171917

19181918
private function doExport($value)
19191919
{
1920-
$export = var_export($value, true);
1920+
if (is_string($value) && false !== strpos($value, "\n")) {
1921+
$cleanParts = explode("\n", $value);
1922+
$cleanParts = array_map(function ($part) { return var_export($part, true); }, $cleanParts);
1923+
$export = implode('."\n".', $cleanParts);
1924+
} else {
1925+
$export = var_export($value, true);
1926+
}
19211927

19221928
if ("'" === $export[0] && $export !== $resolvedExport = $this->container->resolveEnvPlaceholders($export, "'.\$this->getEnv('string:%s').'")) {
19231929
$export = $resolvedExport;

src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public function testDumpOptimizationString()
7171
'optimize concatenation with empty string' => 'string1%empty_value%string2',
7272
'optimize concatenation from the start' => '%empty_value%start',
7373
'optimize concatenation at the end' => 'end%empty_value%',
74+
'new line' => "string with \nnew line",
7475
));
7576
$definition->setPublic(true);
7677

src/Symfony/Component/DependencyInjection/Tests/Fixtures/php/services10.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function isFrozen()
6363
*/
6464
protected function getTestService()
6565
{
66-
return $this->services['test'] = new \stdClass(array('only dot' => '.', 'concatenation as value' => '.\'\'.', 'concatenation from the start value' => '\'\'.', '.' => 'dot as a key', '.\'\'.' => 'concatenation as a key', '\'\'.' => 'concatenation from the start key', 'optimize concatenation' => 'string1-string2', 'optimize concatenation with empty string' => 'string1string2', 'optimize concatenation from the start' => 'start', 'optimize concatenation at the end' => 'end'));
66+
return $this->services['test'] = new \stdClass(array('only dot' => '.', 'concatenation as value' => '.\'\'.', 'concatenation from the start value' => '\'\'.', '.' => 'dot as a key', '.\'\'.' => 'concatenation as a key', '\'\'.' => 'concatenation from the start key', 'optimize concatenation' => 'string1-string2', 'optimize concatenation with empty string' => 'string1string2', 'optimize concatenation from the start' => 'start', 'optimize concatenation at the end' => 'end', 'new line' => 'string with '."\n".'new line'));
6767
}
6868

6969
public function getParameter($name)

src/Symfony/Component/HttpFoundation/IpUtils.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ public static function checkIp4($requestIp, $ip)
8787
$netmask = 32;
8888
}
8989

90+
if (false === ip2long($address)) {
91+
return self::$checkedIps[$cacheKey] = false;
92+
}
93+
9094
return self::$checkedIps[$cacheKey] = 0 === substr_compare(sprintf('%032b', ip2long($requestIp)), sprintf('%032b', ip2long($address)), 0, $netmask);
9195
}
9296

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,21 @@ public function testAnIpv6WithOptionDisabledIpv6()
8282

8383
IpUtils::checkIp('2a01:198:603:0:396e:4789:8e99:890f', '2a01:198:603:0::/65');
8484
}
85+
86+
/**
87+
* @dataProvider invalidIpAddressData
88+
*/
89+
public function testInvalidIpAddressesDoNotMatch($requestIp, $proxyIp)
90+
{
91+
$this->assertFalse(IpUtils::checkIp4($requestIp, $proxyIp));
92+
}
93+
94+
public function invalidIpAddressData()
95+
{
96+
return array(
97+
'invalid proxy wildcard' => array('192.168.20.13', '*'),
98+
10000 'invalid proxy missing netmask' => array('192.168.20.13', '0.0.0.0'),
99+
'invalid request IP with invalid proxy wildcard' => array('0.0.0.0', '*'),
100+
);
101+
}
85102
}

src/Symfony/Component/Translation/Tests/TranslatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class TranslatorTest extends TestCase
2424
*/
2525
public function testConstructorInvalidLocale($locale)
2626
{
27-
$translator = new Translator($locale);
27+
new Translator($locale);
2828
}
2929

3030
/**

src/Symfony/Component/Validator/Constraints/File.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ public function __get($option)
8888
return parent::__get($option);
8989
}
9090

91+
public function __isset($option)
92+
{
93+
if ('maxSize' === $option) {
94+
return true;
95+
}
96+
97+
return parent::__isset($option);
98+
}
99+
91100
private function normalizeBinaryFormat($maxSize)
92101
{
93102
$factors = array(

0 commit comments

Comments
 (0)
0