8000 fix PHP 5.3 compatibility · symfony/symfony@dccf1ee · GitHub
[go: up one dir, main page]

Skip to content

Commit dccf1ee

Browse files
committed
fix PHP 5.3 compatibility
1 parent 8d7e002 commit dccf1ee

17 files changed

+123
-123
lines changed

src/Symfony/Bridge/PhpUnit/ClockMock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public static function register($class)
8383
{
8484
$self = \get_called_class();
8585

86-
$mockedNs = [substr($class, 0, strrpos($class, '\\'))];
86+
$mockedNs = array(substr($class, 0, strrpos($class, '\\')));
8787
if (0 < strpos($class, '\\Tests\\')) {
8888
$ns = str_replace('\\Tests\\', '\\', $class);
8989
$mockedNs[] = substr($ns, 0, strrpos($ns, '\\'));

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ public static function register($mode = 0)
5454
if (false === $mode) {
5555
$mode = getenv('SYMFONY_DEPRECATIONS_HELPER');
5656
}
57-
if (self::MODE_DISABLED !== $mode
58-
&& self::MODE_WEAK !== $mode
59-
&& self::MODE_WEAK_VENDORS !== $mode
57+
if (DeprecationErrorHandler::MODE_DISABLED !== $mode
58+
&& DeprecationErrorHandler::MODE_WEAK !== $mode
59+
&& DeprecationErrorHandler::MODE_WEAK_VENDORS !== $mode
6060
&& (!isset($mode[0]) || '/' !== $mode[0])
6161
) {
6262
$mode = preg_match('/^[1-9][0-9]*$/', $mode) ? (int) $mode : 0;
@@ -92,7 +92,7 @@ public static function register($mode = 0)
9292
return false;
9393
};
9494

95-
$deprecations = [
95+
$deprecations = array(
9696
'unsilencedCount' => 0,
9797
'remainingCount' => 0,
9898
'legacyCount' => 0,
@@ -103,7 +103,7 @@ public static function register($mode = 0)
103103
'legacy' => array(),
104104
'other' => array(),
105105
'remaining vendor' => array(),
106-
];
106+
);
107107
$deprecationHandler = function ($type, $msg, $file, $line, $context = array()) use (&$deprecations, $getMode, $UtilPrefix, $inVendors) {
108108
if ((E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) || DeprecationErrorHandler::MODE_DISABLED === $mode = $getMode()) {
109109
$ErrorHandler = $UtilPrefix.'ErrorHandler';
@@ -113,7 +113,7 @@ public static function register($mode = 0)
113113

114114
$trace = debug_backtrace();
115115
$group = 'other';
116-
$isVendor = self::MODE_WEAK_VENDORS === $mode && $inVendors($file);
116+
$isVendor = DeprecationErrorHandler::MODE_WEAK_VENDORS === $mode && $inVendors($file);
117117

118118
$i = \count($trace);
119119
while (1 < $i && (!isset($trace[--$i]['class']) || ('ReflectionMethod' === $trace[$i]['class'] || 0 === strpos($trace[$i]['class'], 'PHPUnit_') || 0 === strpos($trace[$i]['class'], 'PHPUnit\\')))) {
@@ -130,7 +130,7 @@ public static function register($mode = 0)
130130
// \Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait::endTest()
131131
// then we need to use the serialized information to determine
132132
// if the error has been triggered from vendor code.
133-
$isVendor = self::MODE_WEAK_VENDORS === $mode && isset($parsedMsg['triggering_file']) && $inVendors($parsedMsg['triggering_file']);
133+
$isVendor = DeprecationErrorHandler::MODE_WEAK_VENDORS === $mode && isset($parsedMsg['triggering_file']) && $inVendors($parsedMsg['triggering_file']);
134134
} else {
135135
$class = isset($trace[$i]['object']) ? \get_class($trace[$i]['object']) : $trace[$i]['class'];
136136
$method = $trace[$i]['function'];
@@ -167,13 +167,13 @@ public static function register($mode = 0)
167167

168168
exit(1);
169169
}
170-
if ('legacy' !== $group && self::MODE_WEAK !== $mode) {
170+
if ('legacy' !== $group && DeprecationErrorHandler::MODE_WEAK !== $mode) {
171171
$ref = &$deprecations[$group][$msg]['count'];
172172
++$ref;
173173
$ref = &$deprecations[$group][$msg][$class.'::'.$method];
174174
++$ref;
175175
}
176-
} elseif (self::MODE_WEAK !== $mode) {
176+
} elseif (DeprecationErrorHandler::MODE_WEAK !== $mode) {
177177
$ref = &$deprecations[$group][$msg]['count'];
178178
++$ref;
179179
}
@@ -183,7 +183,7 @@ public static function register($mode = 0)
183183

184184
if (null !== $oldErrorHandler) {
185185
restore_error_handler();
186-
if ([$UtilPrefix.'ErrorHandler', 'handleError'] === $oldErrorHandler) {
186+
if (array($UtilPrefix.'ErrorHandler', 'handleError') === $oldErrorHandler) {
187187
restore_error_handler();
188188
self::register($mode);
189189
}
@@ -206,7 +206,7 @@ public static function register($mode = 0)
206206
$currErrorHandler = set_error_handler('var_dump');
207207
restore_error_handler();
208208

209-
if (self::MODE_WEAK === $mode) {
209+
if (DeprecationErrorHandler::MODE_WEAK === $mode) {
210210
$colorize = function ($str) { return $str; };
211211
}
212212
if ($currErrorHandler !== $deprecationHandler) {
@@ -217,8 +217,8 @@ public static function register($mode = 0)
217217
return $b['count'] - $a['count'];
218218
};
219219

220-
$groups = ['unsilenced', 'remaining'];
221-
if (self::MODE_WEAK_VENDORS === $mode) {
220+
$groups = array('unsilenced', 'remaining');
221+
if (DeprecationErrorHandler::MODE_WEAK_VENDORS === $mode) {
222222
$groups[] = 'remaining vendor';
223223
}
224224
array_push($groups, 'legacy', 'other');
@@ -254,11 +254,11 @@ public static function register($mode = 0)
254254
$displayDeprecations($deprecations);
255255

256256
// store failing status
257-
$isFailing = self::MODE_WEAK !== $mode && $mode < $deprecations['unsilencedCount'] + $deprecations['remainingCount'] + $deprecations['otherCount'];
257+
$isFailing = DeprecationErrorHandler::MODE_WEAK !== $mode && $mode < $deprecations['unsilencedCount'] + $deprecations['remainingCount'] + $deprecations['otherCount'];
258258

259259
// reset deprecations array
260260
foreach ($deprecations as $group => $arrayOrInt) {
261-
$deprecations[$group] = \is_int($arrayOrInt) ? 0 : [];
261+
$deprecations[$group] = \is_int($arrayOrInt) ? 0 : array();
262262
}
263263

264264
register_shutdown_function(function () use (&$deprecations, $isFailing, $displayDeprecations, $mode) {
@@ -269,7 +269,7 @@ public static function register($mode = 0)
269269
}
270270
}
271271
$displayDeprecations($deprecations);
272-
if ($isFailing || self::MODE_WEAK !== $mode && $mode < $deprecations['unsilencedCount'] + $deprecations['remainingCount'] + $deprecations['otherCount']) {
272+
if ($isFailing || DeprecationErrorHandler::MODE_WEAK !== $mode && $mode < $deprecations['unsilencedCount'] + $deprecations['remainingCount'] + $deprecations['otherCount']) {
273273
exit(1);
274274
}
275275
});
@@ -279,8 +279,8 @@ public static function register($mode = 0)
279279

280280
public static function collectDeprecations($outputFile)
281281
{
282-
$deprecations = [];
283-
$previousErrorHandler = set_error_handler(function ($type, $msg, $file, $line, $context = []) use (&$deprecations, &$previousErrorHandler) {
282+
$deprecations = array();
283+
$previousErrorHandler = set_error_handler(function ($type, $msg, $file, $line, $context = array()) use (&$deprecations, &$previousErrorHandler) {
284284
if (E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) {
285285
if ($previousErrorHandler) {
286286
return $previousErrorHandler($type, $msg, $file, $line, $context);
@@ -292,7 +292,7 @@ public static function collectDeprecations($outputFile)
292292

293293
return $ErrorHandler::handleError($type, $msg, $file, $line, $context);
294294
}
295-
$deprecations[] = [error_reporting(), $msg, $file];
295+
$deprecations[] = array(error_reporting(), $msg, $file);
296296
});
297297

298298
register_shutdown_function(function () use ($outputFile, &$deprecations) {

src/Symfony/Bridge/PhpUnit/DnsMock.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
*/
1717
class DnsMock
1818
{
19-
private static $hosts = [];
20-
private static $dnsTypes = [
19+
private static $hosts = array();
20+
private static $dnsTypes = array(
2121
'A' => DNS_A,
2222
'MX' => DNS_MX,
2323
'NS' => DNS_NS,
@@ -30,7 +30,7 @@ class DnsMock
3030
'NAPTR' => DNS_NAPTR,
3131
'TXT' => DNS_TXT,
3232
'HINFO' => DNS_HINFO,
33-
];
33+
);
3434

3535
/**
3636
* Configures the mock values for DNS queries.
@@ -68,7 +68,7 @@ public static function getmxrr($hostname, &$mxhosts, &$weight = null)
6868
if (!self::$hosts) {
6969
return \getmxrr($hostname, $mxhosts, $weight);
7070
}
71-
$mxhosts = $weight = [];
71+
$mxhosts = $weight = array();
7272

7373
if (isset(self::$hosts[$hostname])) {
7474
foreach (self::$hosts[$hostname] as $record) {
@@ -125,7 +125,7 @@ public static function gethostbynamel($hostname)
125125
$ips = false;
126126

127127
if (isset(self::$hosts[$hostname])) {
128-
$ips = [];
128+
$ips = array();
129129

130130
foreach (self::$hosts[$hostname] as $record) {
131131
if ('A' === $record['type']) {
@@ -149,11 +149,11 @@ public static function dns_get_record($hostname, $type = DNS_ANY, &$authns = nul
149149
if (DNS_ANY === $type) {
150150
$type = DNS_ALL;
151151
}
152-
$records = [];
152+
$records = array();
153153

154154
foreach (self::$hosts[$hostname] as $record) {
155155
if (isset(self::$dnsTypes[$record['type']]) && (self::$dnsTypes[$record['type']] & $type)) {
156-
$records[] = array_merge(['host' => $hostname, 'class' => 'IN', 'ttl' => 1, 'type' => $record['type']], $record);
156+
$records[] = array_merge(array('host' => $hostname, 'class' => 'IN', 'ttl' => 1, 'type' => $record['type']), $record);
157157
}
158158
}
159159
}
@@ -165,7 +165,7 @@ public static function register($class)
165165
{
166166
$self = \get_called_class();
167167

168-
$mockedNs = [substr($class, 0, strrpos($class, '\\'))];
168+
$mockedNs = array(substr($class, 0, strrpos($class, '\\')));
169169
if (0 < strpos($class, '\\Tests\\')) {
170170
$ns = str_replace('\\Tests\\', '\\', $class);
171171
$mockedNs[] = substr($ns, 0, strrpos($ns, '\\'));

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function __construct(callable $sutFqcnResolver = null, $warningOnSutNotFo
3131
{
3232
$this->sutFqcnResolver = $sutFqcnResolver;
3333
$this->warningOnSutNotFound = $warningOnSutNotFound;
34-
$this->warnings = [];
34+
$this->warnings = array();
3535
}
3636

3737
public function startTest($test)
@@ -42,7 +42,7 @@ public function startTest($test)
4242

4343
$annotations = $test->getAnnotations();
4444

45-
$ignoredAnnotations = ['covers', 'coversDefaultClass', 'coversNothing'];
45+
$ignoredAnnotations = array('covers', 'coversDefaultClass', 'coversNothing');
4646

4747
foreach ($ignoredAnnotations as $annotation) {
4848
if (isset($annotations['class'][$annotation]) || isset($annotations['method'][$annotation])) {
@@ -74,11 +74,11 @@ public function startTest($test)
7474
$r->setAccessible(true);
7575

7676
$cache = $r->getValue();
77-
$cache = array_replace_recursive($cache, [
78-
\get_class($test) => [
79-
'covers' => [$sutFqcn],
80-
],
81-
]);
77+
$cache = array_replace_recursive($cache, array(
78+
\get_class($test) => array(
79+
'covers' => array($sutFqcn),
80+
),
81+
));
8282
$r->setValue($testClass, $cache);
8383
}
8484

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class SymfonyTestsListenerForV5 extends \PHPUnit_Framework_BaseTestListener
2222
{
2323
private $trait;
2424

25-
public function __construct(array $mockedNamespaces = [])
25+
public function __construct(array $mockedNamespaces = array())
2626
{
2727
$this->trait = new SymfonyTestsListenerTrait($mockedNamespaces);
2828
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class SymfonyTestsListenerForV6 extends BaseTestListener
2727
{
2828
private $trait;
2929

30-
public function __construct(array $mockedNamespaces = [])
30+
public function __construct(array $mockedNamespaces = array())
3131
{
3232
$this->trait = new SymfonyTestsListenerTrait($mockedNamespaces);
3333
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class SymfonyTestsListenerForV7 implements TestListener
3030

3131
private $trait;
3232

33-
public function __construct(array $mockedNamespaces = [])
33+
public function __construct(array $mockedNamespaces = array())
3434
{
3535
$this->trait = new SymfonyTestsListenerTrait($mockedNamespaces);
3636
}

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ class SymfonyTestsListenerTrait
3232
private static $globallyEnabled = false;
3333
private $state = -1;
3434
private $skippedFile = false;
35-
private $wasSkipped = [];
36-
private $isSkipped = [];
37-
private $expectedDeprecations = [];
38-
private $gatheredDeprecations = [];
35+
private $wasSkipped = array();
36+
private $isSkipped = array();
37+
private $expectedDeprecations = array();
38+
private $gatheredDeprecations = array();
3939
private $previousErrorHandler;
4040
private $testsWithWarnings;
4141
private $reportUselessTests;
@@ -45,7 +45,7 @@ class SymfonyTestsListenerTrait
4545
/**
4646
* @param array $mockedNamespaces List of namespaces, indexed by mocked features (time-sensitive or dns-sensitive)
4747
*/
48-
public function __construct(array $mockedNamespaces = [])
48+
public function __construct(array $mockedNamespaces = array())
4949
{
5050
if (class_exists('PHPUnit_Util_Blacklist')) {
5151
\PHPUnit_Util_Blacklist::$blacklistedClassNames['\Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait'] = 2;
@@ -57,7 +57,7 @@ public function __construct(array $mockedNamespaces = [])
5757

5858
foreach ($mockedNamespaces as $type => $namespaces) {
5959
if (!\is_array($namespaces)) {
60-
$namespaces = [$namespaces];
60+
$namespaces = array($namespaces);
6161
}
6262
if ('time-sensitive' === $type) {
6363
foreach ($namespaces as $ns) {
@@ -104,7 +104,7 @@ public function startTestSuite($suite)
104104
$Test = 'PHPUnit\Util\Test';
105105
}
106106
$suiteName = $suite->getName();
107-
$this->testsWithWarnings = [];
107+
$this->testsWithWarnings = array();
108108

109109
foreach ($suite->tests() as $test) {
110110
if (!($test instanceof \PHPUnit\Framework\TestCase || $test instanceof TestCase)) {
@@ -135,11 +135,11 @@ public function startTestSuite($suite)
135135

136136
if (!$this->wasSkipped = require $this->skippedFile) {
137137
echo "All tests already ran successfully.\n";
138-
$suite->setTests([]);
138+
$suite->setTests(array());
139139
}
140140
}
141141
}
142-
$testSuites = [$suite];
142+
$testSuites = array($suite);
143143
for ($i = 0; isset($testSuites[$i]); ++$i) {
144144
foreach ($testSuites[$i]->tests() as $test) {
145145
if ($test instanceof \PHPUnit_Framework_TestSuite || $test instanceof TestSuite) {
@@ -158,7 +158,7 @@ public function startTestSuite($suite)
158158
}
159159
}
160160
} elseif (2 === $this->state) {
161-
$skipped = [];
161+
$skipped = array();
162162
foreach ($suite->tests() as $test) {
163163
if (!($test instanceof \PHPUnit\Framework\TestCase || $test instanceof TestCase)
164164
|| isset($this->wasSkipped[$suiteName]['*'])
@@ -230,7 +230,7 @@ public function startTest($test)
230230
$test->getTestResultObject()->beStrictAboutTestsThatDoNotTestAnything(false);
231231

232232
$this->expectedDeprecations = $annotations['method']['expectedDeprecation'];
233-
$this->previousErrorHandler = set_error_handler([$this, 'handleError']);
233+
$this->previousErrorHandler = set_error_handler(array($this, 'handleError'));
234234
}
235235
}
236236
}
@@ -271,8 +271,8 @@ public function endTest($test, $time)
271271
$deprecations = file_get_contents($this->runsInSeparateProcess);
272272
unlink($this->runsInSeparateProcess);
273273
putenv('SYMFONY_DEPRECATIONS_SERIALIZE');
274-
foreach ($deprecations ? unserialize($deprecations) : [] as $deprecation) {
275-
$error = serialize(['deprecation' => $deprecation[1], 'class' => $className, 'method' => $test->getName(false), 'triggering_file' => isset($deprecation[2]) ? $deprecation[2] : null]);
274+
foreach ($deprecations ? unserialize($deprecations) : array() as $deprecation) {
275+
$error = serialize(array('deprecation' => $deprecation[1], 'class' => $className, 'method' => $test->getName(false), 'triggering_file' => isset($deprecation[2]) ? $deprecation[2] : null));
276276
if ($deprecation[0]) {
277277
@trigger_error($error, E_USER_DEPRECATED);
278278
} else {
@@ -283,13 +283,13 @@ public function endTest($test, $time)
283283
}
284284

285285
if ($this->expectedDeprecations) {
286-
if (!\in_array($test->getStatus(), [$BaseTestRunner::STATUS_SKIPPED, $BaseTestRunner::STATUS_INCOMPLETE], true)) {
286+
if (!\in_array($test->getStatus(), array($BaseTestRunner::STATUS_SKIPPED, $BaseTestRunner::STATUS_INCOMPLETE), true)) {
287287
$test->addToAssertionCount(\count($this->expectedDeprecations));
288288
}
289289

290290
restore_error_handler();
291291

292-
if (!$errored && !\in_array($test->getStatus(), [$BaseTestRunner::STATUS_SKIPPED, $BaseTestRunner::STATUS_INCOMPLETE, $BaseTestRunner::STATUS_FAILURE, $BaseTestRunner::STATUS_ERROR], true)) {
292+
if (!$errored && !\in_array($test->getStatus(), array($BaseTestRunner::STATUS_SKIPPED, $BaseTestRunner::STATUS_INCOMPLETE, $BaseTestRunner::STATUS_FAILURE, $BaseTestRunner::STATUS_ERROR), true)) {
293293
try {
294294
$prefix = "@expectedDeprecation:\n";
295295
$test->assertStringMatchesFormat($prefix.'%A '.implode("\n%A ", $this->expectedDeprecations)."\n%A", $prefix.' '.implode("\n ", $this->gatheredDeprecations)."\n");
@@ -300,20 +300,20 @@ public function endTest($test, $time)
300300
}
301301
}
302302

303-
$this->expectedDeprecations = $this->gatheredDeprecations = [];
303+
$this->expectedDeprecations = $this->gatheredDeprecations = array();
304304
$this->previousErrorHandler = null;
305305
}
306306
if (!$this->runsInSeparateProcess && -2 < $this->state && ($test instanceof \PHPUnit\Framework\TestCase || $test instanceof TestCase)) {
307307
if (\in_array('time-sensitive', $groups, true)) {
308308
ClockMock::withClockMock(false);
309309
}
310310
if (\in_array('dns-sensitive', $groups, true)) {
311-
DnsMock::withMockedHosts([]);
311+
DnsMock::withMockedHosts(array());
312312
}
313313
}
314314
}
315315

316-
public function handleError($type, $msg, $file, $line, $context = [])
316+
public function handleError($type, $msg, $file, $line, $context = array())
317317
{
318318
if (E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) {
319319
$h = $this->previousErrorHandler;

0 commit comments

Comments
 (0)
0