8000 Merge branch '4.4' into 5.1 · symfony/symfony@58f3302 · GitHub
[go: up one dir, main page]

Skip to content

Commit 58f3302

Browse files
Merge branch '4.4' into 5.1
* 4.4: [PhpUnitBridge] CS fix [PhpUnitBridge] Fix PHP 5.5 compatibility Add missing param annotation abouts $fileLinkFormat [Form] Fixed StringUtil::trim() to trim ZERO WIDTH SPACE (U+200B) and SOFT HYPHEN (U+00AD) 23412 Stop treating multiline resources as globs
2 parents 56f0456 + 52a0233 commit 58f3302

File tree

21 files changed

+92
-63
lines changed

21 files changed

+92
-63
lines changed

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler/Deprecation.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Deprecation
4141

4242
/**
4343
* @var string[] Absolute paths to source or tests of the project, cache
44-
* directories exlcuded because it is based on autoloading
44+
* directories excluded because it is based on autoloading
4545
* rules and cache systems typically do not use those
4646
*/
4747
private static $internalPaths = [];
@@ -61,10 +61,10 @@ public function __construct($message, array $trace, $file)
6161

6262
$this->trace = $trace;
6363

64-
if ('trigger_error' === ($trace[1]['function'] ?? null)
65-
&& (DebugClassLoader::class === ($class = $trace[2]['class'] ?? null) || LegacyDebugClassLoader::class === $class)
66-
&& 'checkClass' === ($trace[2]['function'] ?? null)
67-
&& null !== ($extraFile = $trace[2]['args'][1] ?? null)
64+
if ('trigger_error' === (isset($trace[1]['function']) ? $trace[1]['function'] : null)
65+
&& (DebugClassLoader::class === ($class = (isset($trace[2]['class']) ? $trace[2]['class'] : null)) || LegacyDebugClassLoader::class === $class)
66+
&& 'checkClass' === (isset($trace[2]['function']) ? $trace[2]['function'] : null)
67+
&& null !== ($extraFile = (isset($trace[2]['args'][1]) ? $trace[2]['args'][1] : null))
6868
&& '' !== $extraFile
6969
&& false !== $extraFile = realpath($extraFile)
7070
) {

src/Symfony/Bridge/PhpUnit/DnsMock.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ class DnsMock
1818
{
1919
private static $hosts = [];
2020
private static $dnsTypes = [
21-
'A' => DNS_A,
22-
'MX' => DNS_MX,
23-
'NS' => DNS_NS,
24-
'SOA' => DNS_SOA,
25-
'PTR' => DNS_PTR,
26-
'CNAME' => DNS_CNAME,
27-
'AAAA' => DNS_AAAA,
28-
'A6' => DNS_A6,
29-
'SRV' => DNS_SRV,
30-
'NAPTR' => DNS_NAPTR,
31-
'TXT' => DNS_TXT,
32-
'HINFO' => DNS_HINFO,
21+
'A' => \DNS_A,
22+
'MX' => \DNS_MX,
23+
'NS' => \DNS_NS,
24+
'SOA' => \DNS_SOA,
25+
'PTR' => \DNS_PTR,
26+
'CNAME' => \DNS_CNAME,
27+
'AAAA' => \DNS_AAAA,
28+
'A6' => \DNS_A6,
29+
'SRV' => \DNS_SRV,
30+
'NAPTR' => \DNS_NAPTR,
31+
'TXT' => \DNS_TXT,
32+
'HINFO' => \DNS_HINFO,
3333
];
3434

3535
/**
@@ -137,7 +137,7 @@ public static function gethostbynamel($hostname)
137137
return $ips;
138138
}
139139

140-
public static function dns_get_record($hostname, $type = DNS_ANY, &$authns = null, &$addtl = null, $raw = false)
140+
public static function dns_get_record($hostname, $type = \DNS_ANY, &$authns = null, &$addtl = null, $raw = false)
141141
{
142142
if (!self::$hosts) {
143143
return \dns_get_record($hostname, $type, $authns, $addtl, $raw);
@@ -146,8 +146,8 @@ public static function dns_get_record($hostname, $type = DNS_ANY, &$authns = nul
146146
$records = false;
147147

148148
if (isset(self::$hosts[$hostname])) {
149-
if (DNS_ANY === $type) {
150-
$type = DNS_ALL;
149+
if (\DNS_ANY === $type) {
150+
$type = \DNS_ALL;
151151
}
152152
$records = [];
153153

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Bridge\PhpUnit\Legacy;
1313

1414
/**
15-
* @internal use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait instead.
15+
* @internal use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait instead
1616
*/
1717
trait ExpectDeprecationTraitForV8_4
1818
{
@@ -21,7 +21,7 @@ trait ExpectDeprecationTraitForV8_4
2121
*/
2222
public function expectDeprecation(): void
2323
{
24-
if (1 > func_num_args() || !\is_string($message = func_get_arg(0))) {
24+
if (1 > \func_num_args() || !\is_string($message = func_get_arg(0))) {
2525
throw new \InvalidArgumentException(sprintf('The "%s()" method requires the string $message argument.', __FUNCTION__));
2626
}
2727

@@ -48,15 +48,15 @@ public function expectDeprecation(): void
4848
}
4949

5050
/**
51-
* @internal use expectDeprecation() instead.
51+
* @internal use expectDeprecation() instead
5252
*/
5353
public function expectDeprecationMessage(string $message): void
545 B41A 4
{
5555
throw new \BadMethodCallException(sprintf('The "%s()" method is not supported by Symfony\'s PHPUnit Bridge ExpectDeprecationTrait, pass the message to expectDeprecation() instead.', __FUNCTION__));
5656
}
5757

5858
/**
59-
* @internal use expectDeprecation() instead.
59+
* @internal use expectDeprecation() instead
6060
*/
6161
public function expectDeprecationMessageMatches(string $regularExpression): void
6262
{

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

Lines changed: 11 additions & 12 deletions
< F438 /tr>
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
use PHPUnit\Framework\Constraint\IsEqual;
1515
use PHPUnit\Framework\Constraint\LogicalNot;
16-
use PHPUnit\Framework\Constraint\RegularExpression;
1716
use PHPUnit\Framework\Constraint\StringContains;
1817
use PHPUnit\Framework\Constraint\TraversableContains;
1918

@@ -228,7 +227,7 @@ public static function assertStringNotContainsStringIgnoringCase($needle, $hayst
228227
public static function assertFinite($actual, $message = '')
229228
{
230229
static::assertInternalType('float', $actual, $message);
231-
static::assertTrue(is_finite($actual), $message ? $message : "Failed asserting that $actual is finite.");
230+
static::assertTrue(is_finite($actual), $message ?: "Failed asserting that $actual is finite.");
232231
}
233232

234233
/**
@@ -239,7 +238,7 @@ public static function assertFinite($actual, $message = '')
239238
public static function assertInfinite($actual, $message = '')
240239
{
241240
static::assertInternalType('float', $actual, $message);
242-
static::assertTrue(is_infinite($actual), $message ? $message : "Failed asserting that $actual is infinite.");
241+
static::assertTrue(is_infinite($actual), $message ?: "Failed asserting that $actual is infinite.");
243242
}
244243

245244
/**
@@ -250,7 +249,7 @@ public static function assertInfinite($actual, $message = '')
250249
public static function assertNan($actual, $message = '')
251250
{
252251
static::assertInternalType('float', $actual, $message);
253-
static::assertTrue(is_nan($actual), $message ? $message : "Failed asserting that $actual is nan.");
252+
static::assertTrue(is_nan($actual), $message ?: "Failed asserting that $actual is nan.");
254253
}
255254

256255
/**
@@ -262,7 +261,7 @@ public static function assertNan($actual, $message = '')
262261
public static function assertIsReadable($filename, $message = '')
263262
{
264263
static::assertInternalType('string', $filename, $message);
265-
static::assertTrue(is_readable($filename), $message ? $message : "Failed asserting that $filename is readable.");
264+
static::assertTrue(is_readable($filename), $message ?: "Failed asserting that $filename is readable.");
266265
}
267266

268267
/**
@@ -274,7 +273,7 @@ public static function assertIsReadable($filename, $message = '')
274273
public static function assertNotIsReadable($filename, $message = '')
275274
{
276275
static::assertInternalType('string', $filename, $message);
277-
static::assertFalse(is_readable($filename), $message ? $message : "Failed asserting that $filename is not readable.");
276+
static::assertFalse(is_readable($filename), $message ?: "Failed asserting that $filename is not readable.");
278277
}
279278

280279
/**
@@ -297,7 +296,7 @@ public static function assertIsNotReadable($filename, $message = '')
297296
public static function assertIsWritable($filename, $message = '')
298297
{
299298
static::assertInternalType('string', $filename, $message);
300-
static::assertTrue(is_writable($filename), $message ? $message : "Failed asserting that $filename is writable.");
299+
static::assertTrue(is_writable($filename), $message ?: "Failed asserting that $filename is writable.");
301300
}
302301

303302
/**
@@ -309,7 +308,7 @@ public static function assertIsWritable($filename, $message = '')
309308
public static function assertNotIsWritable($filename, $message = '')
310309
{
311310
static::assertInternalType('string', $filename, $message);
312-
static::assertFalse(is_writable($filename), $message ? $message : "Failed asserting that $filename is not writable.");
311+
static::assertFalse(is_writable($filename), $message ?: "Failed asserting that $filename is not writable.");
313312
}
314313

315314
/**
@@ -332,7 +331,7 @@ public static function assertIsNotWritable($filename, $message = '')
332331
public static function assertDirectoryExists($directory, $message = '')
333332
{
334333
static::assertInternalType('string', $directory, $message);
335-
static::assertTrue(is_dir($directory), $message ? $message : "Failed asserting that $directory exists.");
334+
static::assertTrue(is_dir($directory), $message ?: "Failed asserting that $directory exists.");
336335
}
337336

338337
/**
@@ -344,7 +343,7 @@ public static function assertDirectoryExists($directory, $message = '')
344343
public static function assertDirectoryNotExists($directory, $message = '')
345344
{
346345
static::assertInternalType('string', $directory, $message);
347-
static::assertFalse(is_dir($directory), $message ? $message : "Failed asserting that $directory does not exist.");
346+
static::assertFalse(is_dir($directory), $message ?: "Failed asserting that $directory does not exist.");
348347
}
349348

350349
/**
@@ -437,7 +436,7 @@ public static function assertDirectoryIsNotWritable($directory, $message = '')
437436
public static function assertFileExists($filename, $message = '')
438437
{
439438
static::assertInternalType('string', $filename, $message);
440-
static::assertTrue(file_exists($filename), $message ? $message : "Failed asserting that $filename exists.");
439+
static::assertTrue(file_exists($filename), $message ?: "Failed asserting that $filename exists.");
441440
}
442441

443442
/**
@@ -449,7 +448,7 @@ public static function assertFileExists($filename, $message = '')
449448
public static function assertFileNotExists($filename, $message = '')
450449
{
451 10000 450
static::assertInternalType('string', $filename, $message);
452-
static::assertFalse(file_exists($filename), $message ? $message : "Failed asserting that $filename does not exist.");
451+
static::assertFalse(file_exists($filename), $message ?: "Failed asserting that $filename does not exist.");
453452
}
454453

455454
/**

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public function startTest($test)
235235
if (isset($annotations['method']['expectedDeprecation'])) {
236236
self::$expectedDeprecations = $annotations['method']['expectedDeprecation'];
237237
self::$previousErrorHandler = set_error_handler([self::class, 'handleError']);
238-
@trigger_error('Since symfony/phpunit-bridge 5.1: Using "@expectedDeprecation" annotations in tests is deprecated, use the "ExpectDeprecationTrait::expectDeprecation()" method instead.', E_USER_DEPRECATED);
238+
@trigger_error('Since symfony/phpunit-bridge 5.1: Using "@expectedDeprecation" annotations in tests is deprecated, use the "ExpectDeprecationTrait::expectDeprecation()" method instead.', \E_USER_DEPRECATED);
239239
}
240240

241241
if ($this->checkNumAssertions) {
@@ -283,9 +283,9 @@ public function endTest($test, $time)
283283
$error = serialize(['deprecation' => $deprecation[1], 'class' => $className, 'method' => $test->getName(false), 'triggering_file' => isset($deprecation[2]) ? $deprecation[2] : null]);
284284
if ($deprecation[0]) {
285285
// unsilenced on purpose
286-
trigger_error($error, E_USER_DEPRECATED);
286+
trigger_error($error, \E_USER_DEPRECATED);
287287
} else {
288-
@trigger_error($error, E_USER_DEPRECATED);
288+
@trigger_error($error, \E_USER_DEPRECATED);
289289
}
290290
}
291291
$this->runsInSeparateProcess = false;
@@ -324,7 +324,7 @@ public function endTest($test, $time)
324324

325325
public static function handleError($type, $msg, $file, $line, $context = [])
326326
{
327-
if (E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) {
327+
if (\E_USER_DEPRECATED !== $type && \E_DEPRECATED !== $type) {
328328
$h = self::$previousErrorHandler;
329329

330330
return $h ? $h($type, $msg, $file, $line, $context) : false;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<?php
22

3-
@trigger_error('I come from… afar! :D', E_USER_DEPRECATED);
3+
@trigger_error('I come from… afar! :D', \E_USER_DEPRECATED);

src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/fake_app/AppService.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function selfDeprecation(bool $useContracts = false)
2222
if ($useContracts) {
2323
trigger_deprecation('App', '3.0', sprintf('%s is deprecated, use %s_new instead.', ...$args));
2424
} else {
25-
@trigger_error(sprintf('Since App 3.0: %s is deprecated, use %s_new instead.', ...$args), E_USER_DEPRECATED);
25+
@trigger_error(sprintf('Since App 3.0: %s is deprecated, use %s_new instead.', ...$args), \E_USER_DEPRECATED);
2626
}
2727
}
2828

@@ -47,4 +47,3 @@ public function directDeprecations()
4747
$service2->deprecatedApi();
4848
}
4949
}
50-

src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/fake_vendor/acme/lib/SomeService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public function deprecatedApi(bool $useContracts = false)
1212
if ($useContracts) {
1313
trigger_deprecation('acme/lib', '3.0', sprintf('%s is deprecated, use %s_new instead.', ...$args));
1414
} else {
15-
@trigger_error(sprintf('Since acme/lib 3.0: %s is deprecated, use %s_new instead.', ...$args), E_USER_DEPRECATED);
15+
@trigger_error(sprintf('Since acme/lib 3.0: %s is deprecated, use %s_new instead.', ...$args), \E_USER_DEPRECATED);
1616
}
1717
}
1818

src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/fake_vendor/acme/lib/deprecation_riddled.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,22 @@ public static function getGroups()
1313
EOPHP
1414
);
1515

16-
@trigger_error('root deprecation', E_USER_DEPRECATED);
16+
@trigger_error('root deprecation', \E_USER_DEPRECATED);
1717

1818
class FooTestCase
1919
{
2020
public function testLegacyFoo()
2121
{
22-
@trigger_error('silenced foo deprecation', E_USER_DEPRECATED);
23-
trigger_error('unsilenced foo deprecation', E_USER_DEPRECATED);
24-
@trigger_error('silenced foo deprecation', E_USER_DEPRECATED);
25-
trigger_error('unsilenced foo deprecation', E_USER_DEPRECATED);
22+
@trigger_error('silenced foo deprecation', \E_USER_DEPRECATED);
23+
trigger_error('unsilenced foo deprecation', \E_USER_DEPRECATED);
24+
@trigger_error('silenced foo deprecation', \E_USER_DEPRECATED);
25+
trigger_error('unsilenced foo deprecation', \E_USER_DEPRECATED);
2626
}
2727

2828
public function testNonLegacyBar()
2929
{
30-
@trigger_error('silenced bar deprecation', E_USER_DEPRECATED);
31-
trigger_error('unsilenced bar deprecation', E_USER_DEPRECATED);
30+
@trigger_error('silenced bar deprecation', \E_USER_DEPRECATED);
31+
trigger_error('unsilenced bar deprecation', \E_USER_DEPRECATED);
3232
}
3333
}
3434

src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/fake_vendor/bar/lib/AnotherService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public function deprecatedApi(bool $useContracts = false)
1010
if ($useContracts) {
1111
trigger_deprecation('bar/lib', '3.0', sprintf('%s is deprecated, use %s_new instead.', ...$args));
1212
} else {
13-
@trigger_error(sprintf('Since bar/lib 3.0: %s is deprecated, use %s_new instead.', ...$args), E_USER_DEPRECATED);
13+
@trigger_error(sprintf('Since bar/lib 3.0: %s is deprecated, use %s_new instead.', ...$args), \E_USER_DEPRECATED);
1414
}
1515
}
1616
}

src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/fake_vendor/composer/autoload_real.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function loadClass($className)
2727
public function findFile($class)
2828
{
2929
foreach ($this->getPrefixesPsr4() as $prefix => $baseDirs) {
30-
if (strpos($class, $prefix) !== 0) {
30+
if (0 !== strpos($class, $prefix)) {
3131
continue;
3232
}
3333

src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/fake_vendor_bis/composer/autoload_real.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function getPrefixesPsr4()
1717
public function loadClass($className)
1818
{
1919
foreach ($this->getPrefixesPsr4() as $prefix => $baseDirs) {
20-
if (strpos($className, $prefix) !== 0) {
20+
if (0 !== strpos($className, $prefix)) {
2121
continue;
2222
}
2323

src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/fake_vendor_bis/foo/lib/SomeOtherService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public function deprecatedApi()
88
{
99
@trigger_error(
1010
__FUNCTION__.' from foo is deprecated! You should stop relying on it!',
11-
E_USER_DEPRECATED
11+
\E_USER_DEPRECATED
1212
);
1313
}
1414
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?php
22

3-
$phar = new Phar(__DIR__.DIRECTORY_SEPARATOR.'deprecation.phar', 0, 'deprecation.phar');
4-
$phar->buildFromDirectory(__DIR__.DIRECTORY_SEPARATOR.'deprecation');
3+
$phar = new Phar(__DIR__.\DIRECTORY_SEPARATOR.'deprecation.phar', 0, 'deprecation.phar');
4+
$phar->buildFromDirectory(__DIR__.\DIRECTORY_SEPARATOR.'deprecation');

src/Symfony/Component/Config/Loader/FileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function getLocator()
7171
*/
7272
public function import($resource, string $type = null, bool $ignoreErrors = false, string $sourceResource = null, $exclude = null)
7373
{
74-
if (\is_string($resource) && \strlen($resource) !== $i = strcspn($resource, '*?{[')) {
74+
if (\is_string($resource) && \strlen($resource) !== ($i = strcspn($resource, '*?{[')) && false === strpos($resource, "\n")) {
7575
$excluded = [];
7676
foreach ((array) $exclude as $pattern) {
7777
foreach ($this->glob($pattern, true, $_, false, true) as $path => $info) {

src/Symfony/Component/Config/Tests/Loader/FileLoaderTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,31 @@ public function testImportWithGlobLikeResource()
7777
$this->assertSame('[foo]', $loader->import('[foo]'));
7878
}
7979

80+
public function testImportWithGlobLikeResourceWhichContainsSlashes()
81+
{
82+
$locatorMock = $this->getMockBuilder('Symfony\Component\Config\FileLocatorInterface')->getMock();
83+
$locatorMock->expects($this->once())->method('locate')->willReturn('');
84+
$loader = new TestFileLoader($locatorMock);
85+
86+
$this->assertNull($loader->import('foo/bar[foo]'));
87+
}
88+
89+
public function testImportWithGlobLikeResourceWhichContainsMultipleLines()
90+
{
91+
$locatorMock = $this->getMockBuilder('Symfony\Component\Config\FileLocatorInterface')->getMock();
92+
$loader = new TestFileLoader($locatorMock);
93+
94+
$this->assertSame("foo\nfoobar[foo]", $loader->import("foo\nfoobar[foo]"));
95+
}
96+
97+
public function testImportWithGlobLikeResourceWhichContainsSlashesAndMultipleLines()
98+
{
99+
$locatorMock = $this->getMockBuilder('Symfony\Component\Config\FileLocatorInterface')->getMock();
100+
$loader = new TestFileLoader($locatorMock);
101+
102+
$this->assertSame("foo\nfoo/bar[foo]", $loader->import("foo\nfoo/bar[foo]"));
103+
}
104+
80105
public function testImportWithNoGlobMatch()
81106
{
82107
$locatorMock = $this->getMockBuilder('Symfony\Component\Config\FileLocatorInterface')->getMock();

0 commit comments

Comments
 (0)
0