Skip to content

Commit a110b32

Browse files
Merge branch '2.7' into 2.8
* 2.7: [Bridge\PhpUnit] Exit as late as possible Update Repository Symlink Helper Document explicitly that dotfiles and vcs files are ignored by default do not mock the container builder in tests
2 parents 63825ca + 575971e commit a110b32

File tree

3 files changed

+133
-16
lines changed

3 files changed

+133
-16
lines changed

DeprecationErrorHandler.php

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -161,32 +161,53 @@ public static function register($mode = 0)
161161
return $b['count'] - $a['count'];
162162
};
163163

164-
foreach (array('unsilenced', 'remaining', 'legacy', 'other') as $group) {
165-
if ($deprecations[$group.'Count']) {
166-
echo "\n", $colorize(sprintf('%s deprecation notices (%d)', ucfirst($group), $deprecations[$group.'Count']), 'legacy' !== $group), "\n";
164+
$displayDeprecations = function ($deprecations) use ($colorize, $cmp) {
165+
foreach (array('unsilenced', 'remaining', 'legacy', 'other') as $group) {
166+
if ($deprecations[$group.'Count']) {
167+
echo "\n", $colorize(sprintf('%s deprecation notices (%d)', ucfirst($group), $deprecations[$group.'Count']), 'legacy' !== $group), "\n";
167168

168-
uasort($deprecations[$group], $cmp);
169+
uasort($deprecations[$group], $cmp);
169170

170-
foreach ($deprecations[$group] as $msg => $notices) {
171-
echo "\n ", $notices['count'], 'x: ', $msg, "\n";
171+
foreach ($deprecations[$group] as $msg => $notices) {
172+
echo "\n ", $notices['count'], 'x: ', $msg, "\n";
172173

173-
arsort($notices);
174+
arsort($notices);
174175

175-
foreach ($notices as $method => $count) {
176-
if ('count' !== $method) {
177-
echo ' ', $count, 'x in ', preg_replace('/(.*)\\\\(.*?::.*?)$/', '$2 from $1', $method), "\n";
176+
foreach ($notices as $method => $count) {
177+
if ('count' !== $method) {
178+
echo ' ', $count, 'x in ', preg_replace('/(.*)\\\\(.*?::.*?)$/', '$2 from $1', $method), "\n";
179+
}
178180
}
179181
}
180182
}
181183
}
182-
}
183-
if (!empty($notices)) {
184-
echo "\n";
185-
}
184+
if (!empty($notices)) {
185+
echo "\n";
186+
}
187+
};
186188

187-
if (DeprecationErrorHandler::MODE_WEAK !== $mode && $mode < $deprecations['unsilencedCount'] + $deprecations['remainingCount'] + $deprecations['otherCount']) {
188-
exit(1);
189+
$displayDeprecations($deprecations);
190+
191+
// store failing status
192+
$isFailing = DeprecationErrorHandler::MODE_WEAK !== $mode && $mode < $deprecations['unsilencedCount'] + $deprecations['remainingCount'] + $deprecations['otherCount'];
193+
194+
// reset deprecations array
195+
foreach ($deprecations as $group => $arrayOrInt) {
196+
$deprecations[$group] = is_int($arrayOrInt) ? 0 : array();
189197
}
198+
199+
register_shutdown_function(function () use (&$deprecations, $isFailing, $displayDeprecations, $mode) {
200+
foreach ($deprecations as $group => $arrayOrInt) {
201+
if (0 < (is_int($arrayOrInt) ? $arrayOrInt : count($arrayOrInt))) {
202+
echo "Shutdown-time deprecations:\n";
203+
break;
204+
}
205+
}
206+
$displayDeprecations($deprecations);
207+
if ($isFailing || DeprecationErrorHandler::MODE_WEAK !== $mode && $mode < $deprecations['unsilencedCount'] + $deprecations['remainingCount'] + $deprecations['otherCount']) {
208+
exit(1);
209+
}
210+
});
190211
});
191212
}
192213
}

Tests/DeprecationErrorHandler/default.phpt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ $foo = new FooTestCase();
5959
$foo->testLegacyFoo();
6060
$foo->testNonLegacyBar();
6161

62+
register_shutdown_function(function () {
63+
exit('I get precedence over any exit statements inside the deprecation error handler.');
64+
});
65+
6266
?>
6367
--EXPECTF--
6468
Unsilenced deprecation notices (3)
@@ -80,3 +84,4 @@ Other deprecation notices (1)
8084

8185
1x: root deprecation
8286

87+
I get precedence over any exit statements inside the deprecation error handler.
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
--TEST--
2+
Test DeprecationErrorHandler in default mode
3+
--FILE--
4+
<?php
5+
6+
putenv('SYMFONY_DEPRECATIONS_HELPER');
7+
putenv('ANSICON');
8+
putenv('ConEmuANSI');
9+
putenv('TERM');
10+
11+
$vendor = __DIR__;
12+
while (!file_exists($vendor.'/vendor')) {
13+
$vendor = dirname($vendor);
14+
}
15+
define('PHPUNIT_COMPOSER_INSTALL', $vendor.'/vendor/autoload.php');
16+
require PHPUNIT_COMPOSER_INSTALL;
17+
require_once __DIR__.'/../../bootstrap.php';
18+
19+
@trigger_error('root deprecation', E_USER_DEPRECATED);
20+
21+
eval(<<<'EOPHP'
22+
namespace PHPUnit\Util;
23+
24+
class Test
25+
{
26+
public static function getGroups()
27+
{
28+
return array();
29+
}
30+
}
31+
EOPHP
32+
);
33+
34+
class PHPUnit_Util_Test
35+
{
36+
public static function getGroups()
37+
{
38+
return array();
39+
}
40+
}
41+
42+
class FooTestCase
43+
{
44+
public function testLegacyFoo()
45+
{
46+
@trigger_error('silenced foo deprecation', E_USER_DEPRECATED);
47+
trigger_error('unsilenced foo deprecation', E_USER_DEPRECATED);
48+
trigger_error('unsilenced foo deprecation', E_USER_DEPRECATED);
49+
}
50+
51+
public function testNonLegacyBar()
52+
{
53+
@trigger_error('silenced bar deprecation', E_USER_DEPRECATED);
54+
trigger_error('unsilenced bar deprecation', E_USER_DEPRECATED);
55+
}
56+
}
57+
58+
$foo = new FooTestCase();
59+
$foo->testLegacyFoo();
60+
$foo->testNonLegacyBar();
61+
62+
register_shutdown_function(function () {
63+
@trigger_error('root deprecation during shutdown', E_USER_DEPRECATED);
64+
});
65+
66+
?>
67+
--EXPECTF--
68+
Unsilenced deprecation notices (3)
69+
70+
2x: unsilenced foo deprecation
71+
2x in FooTestCase::testLegacyFoo
72+
73+
1x: unsilenced bar deprecation
74+
1x in FooTestCase::testNonLegacyBar
75+
76+
Remaining deprecation notices (1)
77+
78+
1x: silenced bar deprecation
79+
1x in FooTestCase::testNonLegacyBar
80+
81+
Legacy deprecation notices (1)
82+
83+
Other deprecation notices (1)
84+
85+
1x: root deprecation
86+
87+
Shutdown-time deprecations:
88+
89+
Other deprecation notices (1)
90+
91+
1x: root deprecation during shutdown

0 commit comments

Comments
 (0)