Skip to content

Commit cbf7f1a

Browse files
Merge branch '5.1'
* 5.1: Enable "native_constant_invocation" CS rule Make AbstractPhpFileCacheWarmer public Fix CS Add a warning comment on ldap empty password Bump Symfony version to 4.4.14 Update VERSION for 4.4.13 Update CHANGELOG for 4.4.13 [PhpunitBridge] Fix deprecation type detection
2 parents 2515d98 + 84efbfb commit cbf7f1a

15 files changed

+174
-57
lines changed

DeprecationErrorHandler.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public static function collectDeprecations($outputFile)
8989
{
9090
$deprecations = [];
9191
$previousErrorHandler = set_error_handler(function ($type, $msg, $file, $line, $context = []) use (&$deprecations, &$previousErrorHandler) {
92-
if (E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type && (E_WARNING !== $type || false === strpos($msg, '" targeting switch is equivalent to "break'))) {
92+
if (\E_USER_DEPRECATED !== $type && \E_DEPRECATED !== $type && (\E_WARNING !== $type || false === strpos($msg, '" targeting switch is equivalent to "break'))) {
9393
if ($previousErrorHandler) {
9494
return $previousErrorHandler($type, $msg, $file, $line, $context);
9595
}
@@ -121,7 +121,7 @@ public static function collectDeprecations($outputFile)
121121
*/
122122
public function handleError($type, $msg, $file, $line, $context = [])
123123
{
124-
if ((E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type && (E_WARNING !== $type || false === strpos($msg, '" targeting switch is equivalent to "break'))) || !$this->getConfiguration()->isEnabled()) {
124+
if ((\E_USER_DEPRECATED !== $type && \E_DEPRECATED !== $type && (\E_WARNING !== $type || false === strpos($msg, '" targeting switch is equivalent to "break'))) || !$this->getConfiguration()->isEnabled()) {
125125
return \call_user_func(self::getPhpUnitErrorHandler(), $type, $msg, $file, $line, $context);
126126
}
127127

@@ -337,7 +337,7 @@ private static function getPhpUnitErrorHandler()
337337
return 'PHPUnit\Util\ErrorHandler::handleError';
338338
}
339339

340-
foreach (debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT | DEBUG_BACKTRACE_IGNORE_ARGS) as $frame) {
340+
foreach (debug_backtrace(\DEBUG_BACKTRACE_PROVIDE_OBJECT | \DEBUG_BACKTRACE_IGNORE_ARGS) as $frame) {
341341
if (isset($frame['object']) && $frame['object'] instanceof TestResult) {
342342
return new ErrorHandler(
343343
$frame['object']->getConvertDeprecationsToExceptions(),
@@ -376,21 +376,21 @@ private static function hasColorSupport()
376376

377377
if (\DIRECTORY_SEPARATOR === '\\') {
378378
return (\function_exists('sapi_windows_vt100_support')
379-
&& sapi_windows_vt100_support(STDOUT))
379+
&& sapi_windows_vt100_support(\STDOUT))
380380
|| false !== getenv('ANSICON')
381381
|| 'ON' === getenv('ConEmuANSI')
382382
|| 'xterm' === getenv('TERM');
383383
}
384384

385385
if (\function_exists('stream_isatty')) {
386-
return stream_isatty(STDOUT);
386+
return stream_isatty(\STDOUT);
387387
}
388388

389389
if (\function_exists('posix_isatty')) {
390-
return posix_isatty(STDOUT);
390+
return posix_isatty(\STDOUT);
391391
}
392392

393-
$stat = fstat(STDOUT);
393+
$stat = fstat(\STDOUT);
394394

395395
// Check if formatted mode is S_IFCHR
396396
return $stat ? 0020000 === ($stat['mode'] & 0170000) : false;

DeprecationErrorHandler/Configuration.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,13 @@ public static function fromUrlEncodedString($serializedConfiguration)
173173
'quiet' => [],
174174
];
175175

176-
if ('' === $normalizedConfiguration['disabled'] || filter_var($normalizedConfiguration['disabled'], FILTER_VALIDATE_BOOLEAN)) {
176+
if ('' === $normalizedConfiguration['disabled'] || filter_var($normalizedConfiguration['disabled'], \FILTER_VALIDATE_BOOLEAN)) {
177177
return self::inDisabledMode();
178178
}
179179

180180
$verboseOutput = [];
181181
foreach (['unsilenced', 'direct', 'indirect', 'self', 'other'] as $group) {
182-
$verboseOutput[$group] = filter_var($normalizedConfiguration['verbose'], FILTER_VALIDATE_BOOLEAN);
182+
$verboseOutput[$group] = filter_var($normalizedConfiguration['verbose'], \FILTER_VALIDATE_BOOLEAN);
183183
}
184184

185185
if (\is_array($normalizedConfiguration['quiet'])) {

DeprecationErrorHandler/Deprecation.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,10 @@ private static function getVendors()
270270
if (file_exists($v.'/composer/installed.json')) {
271271
self::$vendors[] = $v;
272272
$loader = require $v.'/autoload.php';
273-
$paths = self::getSourcePathsFromPrefixes(array_merge($loader->getPrefixes(), $loader->getPrefixesPsr4()));
273+
$paths = self::addSourcePathsFromPrefixes(
274+
array_merge($loader->getPrefixes(), $loader->getPrefixesPsr4()),
275+
$paths
276+
);
274277
}
275278
}
276279
}
@@ -286,15 +289,17 @@ private static function getVendors()
286289
return self::$vendors;
287290
}
288291

289-
private static function getSourcePathsFromPrefixes(array $prefixesByNamespace)
292+
private static function addSourcePathsFromPrefixes(array $prefixesByNamespace, array $paths)
290293
{
291294
foreach ($prefixesByNamespace as $prefixes) {
292295
foreach ($prefixes as $prefix) {
293296
if (false !== realpath($prefix)) {
294-
yield realpath($prefix);
297+
$paths[] = realpath($prefix);
295298
}
296299
}
297300
}
301+
302+
return $paths;
298303
}
299304

300305
/**
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
require_once __DIR__.'/composer/autoload_real.php';
4+
5+
return ComposerAutoloaderInitFakeBis::getLoader();
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
class ComposerLoaderFakeBis
4+
{
5+
public function getPrefixes()
6+
{
7+
return [];
8+
}
9+
10+
public function getPrefixesPsr4()
11+
{
12+
return [
13+
'foo\\lib\\' => [__DIR__.'/../foo/lib/'],
14+
];
15+
}
16+
17+
public function loadClass($className)
18+
{
19+
foreach ($this->getPrefixesPsr4() as $prefix => $baseDirs) {
20+
if (strpos($className, $prefix) !== 0) {
21+
continue;
22+
}
23+
24+
foreach ($baseDirs as $baseDir) {
25+
$file = str_replace([$prefix, '\\'], [$baseDir, '/'], $className.'.php');
26+
if (file_exists($file)) {
27+
require $file;
28+
}
29+
}
30+
}
31+
}
32+
}
33+
34+
class ComposerAutoloaderInitFakeBis
35+
{
36+
private static $loader;
37+
38+
public static function getLoader()
39+
{
40+
if (null === self::$loader) {
41+
self::$loader = new ComposerLoaderFakeBis();
42+
spl_autoload_register([self::$loader, 'loadClass']);
43+
}
44+
45+
return self::$loader;
46+
}
47+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"just here": "for the detection"}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace foo\lib;
4+
5+
class SomeOtherService
6+
{
7+
public function deprecatedApi()
8+
{
9+
@trigger_error(
10+
__FUNCTION__.' from foo is deprecated! You should stop relying on it!',
11+
E_USER_DEPRECATED
12+
);
13+
}
14+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
--TEST--
2+
Test DeprecationErrorHandler with multiple autoload files
3+
--FILE--
4+
<?php
5+
6+
$k = 'SYMFONY_DEPRECATIONS_HELPER';
7+
putenv($k.'='.$_SERVER[$k] = $_ENV[$k] = 'max[self]=0');
8+
putenv('ANSICON');
9+
putenv('ConEmuANSI');
10+
putenv('TERM');
11+
12+
$vendor = __DIR__;
13+
while (!file_exists($vendor.'/vendor')) {
14+
$vendor = dirname($vendor);
15+
}
16+
define('PHPUNIT_COMPOSER_INSTALL', $vendor.'/vendor/autoload.php');
17+
require PHPUNIT_COMPOSER_INSTALL;
18+
require_once __DIR__.'/../../bootstrap.php';
19+
20+
eval(<<<'EOPHP'
21+
namespace PHPUnit\Util;
22+
23+
class Test
24+
{
25+
public static function getGroups()
26+
{
27+
return array();
28+
}
29+
}
30+
EOPHP
31+
);
32+
33+
require __DIR__.'/fake_vendor/autoload.php';
34+
require __DIR__.'/fake_vendor_bis/autoload.php';
35+
36+
(new \App\Services\AppService())->directDeprecations();
37+
?>
38+
--EXPECTF--
39+
Remaining direct deprecation notices (2)
40+
41+
1x: deprecatedApi is deprecated! You should stop relying on it!
42+
1x in AppService::directDeprecations from App\Services
43+
44+
1x: deprecatedApi from foo is deprecated! You should stop relying on it!
45+
1x in AppService::directDeprecations from App\Services

Tests/DnsMockTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ public function testDnsGetRecord()
141141

142142
$this->assertFalse(DnsMock::dns_get_record('foobar.com'));
143143
$this->assertSame($records, DnsMock::dns_get_record('example.com'));
144-
$this->assertSame($records, DnsMock::dns_get_record('example.com', DNS_ALL));
145-
$this->assertSame($records, DnsMock::dns_get_record('example.com', DNS_A | DNS_PTR));
146-
$this->assertSame([$ptr], DnsMock::dns_get_record('example.com', DNS_PTR));
144+
$this->assertSame($records, DnsMock::dns_get_record('example.com', \DNS_ALL));
145+
$this->assertSame($records, DnsMock::dns_get_record('example.com', \DNS_A | \DNS_PTR));
146+
$this->assertSame([$ptr], DnsMock::dns_get_record('example.com', \DNS_PTR));
147147
}
148148
}

Tests/ExpectDeprecationTraitTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ final class ExpectDeprecationTraitTest extends TestCase
2626
public function testOne()
2727
{
2828
$this->expectDeprecation('foo');
29-
@trigger_error('foo', E_USER_DEPRECATED);
29+
@trigger_error('foo', \E_USER_DEPRECATED);
3030
}
3131

3232
/**
@@ -38,7 +38,7 @@ public function testOne()
3838
public function testOneInIsolation()
3939
{
4040
$this->expectDeprecation('foo');
41-
@trigger_error('foo', E_USER_DEPRECATED);
41+
@trigger_error('foo', \E_USER_DEPRECATED);
4242
}
4343

4444
/**
@@ -50,8 +50,8 @@ public function testMany()
5050
{
5151
$this->expectDeprecation('foo');
5252
$this->expectDeprecation('bar');
53-
@trigger_error('foo', E_USER_DEPRECATED);
54-
@trigger_error('bar', E_USER_DEPRECATED);
53+
@trigger_error('foo', \E_USER_DEPRECATED);
54+
@trigger_error('bar', \E_USER_DEPRECATED);
5555
}
5656

5757
/**
@@ -64,8 +64,8 @@ public function testMany()
6464
public function testOneWithAnnotation()
6565
{
6666
$this->expectDeprecation('bar');
67-
@trigger_error('foo', E_USER_DEPRECATED);
68-
@trigger_error('bar', E_USER_DEPRECATED);
67+
@trigger_error('foo', \E_USER_DEPRECATED);
68+
@trigger_error('bar', \E_USER_DEPRECATED);
6969
}
7070

7171
/**
@@ -80,9 +80,9 @@ public function testManyWithAnnotation()
8080
{
8181
$this->expectDeprecation('ccc');
8282
$this->expectDeprecation('fcy');
83-
@trigger_error('foo', E_USER_DEPRECATED);
84-
@trigger_error('bar', E_USER_DEPRECATED);
85-
@trigger_error('ccc', E_USER_DEPRECATED);
86-
@trigger_error('fcy', E_USER_DEPRECATED);
83+
@trigger_error('foo', \E_USER_DEPRECATED);
84+
@trigger_error('bar', \E_USER_DEPRECATED);
85+
@trigger_error('ccc', \E_USER_DEPRECATED);
86+
@trigger_error('fcy', \E_USER_DEPRECATED);
8787
}
8888
}

0 commit comments

Comments
 (0)