Skip to content

Commit 8ed107d

Browse files
Merge branch '2.8' into 3.4
* 2.8: [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 fd1d6d1 + e490d66 commit 8ed107d

File tree

11 files changed

+251
-268
lines changed

11 files changed

+251
-268
lines changed

link

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ if (!is_dir("$argv[1]/vendor/symfony")) {
3737
$sfPackages = array('symfony/symfony' => __DIR__);
3838

3939
$filesystem = new Filesystem();
40-
foreach (glob(__DIR__.'/src/Symfony/{Bundle,Bridge,Component,Component/Security}/*', GLOB_BRACE | GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
40+
$braces = array('Bundle', 'Bridge', 'Component', 'Component/Security');
41+
$directories = call_user_func_array('array_merge', array_values(array_map(function ($part) {
42+
return glob(__DIR__.'/src/Symfony/'.$part.'/*', GLOB_ONLYDIR | GLOB_NOSORT);
43+
}, $braces)));
44+
45+
foreach ($directories as $dir) {
4146
if ($filesystem->exists($composer = "$dir/composer.json")) {
4247
$sfPackages[json_decode(file_get_contents($composer))->name] = $dir;
4348
}

src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -215,41 +215,62 @@ public static function register($mode = 0)
215215
return $b['count'] - $a['count'];
216216
};
217217

218-
$groups = array('unsilenced', 'remaining');
219-
if (DeprecationErrorHandler::MODE_WEAK_VENDORS === $mode) {
220-
$groups[] = 'remaining vendor';
221-
}
222-
array_push($groups, 'legacy', 'other');
218+
$displayDeprecations = function ($deprecations) use ($colorize, $cmp) {
219+
$groups = array('unsilenced', 'remaining');
220+
if (DeprecationErrorHandler::MODE_WEAK_VENDORS === $mode) {
221+
$groups[] = 'remaining vendor';
222+
}
223+
array_push($groups, 'legacy', 'other');
223224

224-
foreach ($groups as $group) {
225-
if ($deprecations[$group.'Count']) {
226-
echo "\n", $colorize(
227-
sprintf('%s deprecation notices (%d)', ucfirst($group), $deprecations[$group.'Count']),
228-
'legacy' !== $group && 'remaining vendor' !== $group
229-
), "\n";
225+
foreach ($groups as $group) {
226+
if ($deprecations[$group.'Count']) {
227+
echo "\n", $colorize(
228+
sprintf('%s deprecation notices (%d)', ucfirst($group), $deprecations[$group.'Count']),
229+
'legacy' !== $group && 'remaining vendor' !== $group
230+
), "\n";
230231

231-
uasort($deprecations[$group], $cmp);
232+
uasort($deprecations[$group], $cmp);
232233

233-
foreach ($deprecations[$group] as $msg => $notices) {
234-
echo "\n ", $notices['count'], 'x: ', $msg, "\n";
234+
foreach ($deprecations[$group] as $msg => $notices) {
235+
echo "\n ", $notices['count'], 'x: ', $msg, "\n";
235236

236-
arsort($notices);
237+
arsort($notices);
237238

238-
foreach ($notices as $method => $count) {
239-
if ('count' !== $method) {
240-
echo ' ', $count, 'x in ', preg_replace('/(.*)\\\\(.*?::.*?)$/', '$2 from $1', $method), "\n";
239+
foreach ($notices as $method => $count) {
240+
if ('count' !== $method) {
241+
echo ' ', $count, 'x in ', preg_replace('/(.*)\\\\(.*?::.*?)$/', '$2 from $1', $method), "\n";
242+
}
241243
}
242244
}
243245
}
244246
}
245-
}
246-
if (!empty($notices)) {
247-
echo "\n";
248-
}
247+
if (!empty($notices)) {
248+
echo "\n";
249+
}
250+
};
249251

250-
if (DeprecationErrorHandler::MODE_WEAK !== $mode && $mode < $deprecations['unsilencedCount'] + $deprecations['remainingCount'] + $deprecations['otherCount']) {
251-
exit(1);
252+
$displayDeprecations($deprecations);
253+
254+
// store failing status
255+
$isFailing = DeprecationErrorHandler::MODE_WEAK !== $mode && $mode < $deprecations['unsilencedCount'] + $deprecations['remainingCount'] + $deprecations['otherCount'];
256+
257+
// reset deprecations array
258+
foreach ($deprecations as $group => $arrayOrInt) {
259+
$deprecations[$group] = is_int($arrayOrInt) ? 0 : array();
252260
}
261+
262+
register_shutdown_function(function () use (&$deprecations, $isFailing, $displayDeprecations, $mode) {
263+
foreach ($deprecations as $group => $arrayOrInt) {
264+
if (0 < (is_int($arrayOrInt) ? $arrayOrInt : count($arrayOrInt))) {
265+
echo "Shutdown-time deprecations:\n";
266+
break;
267+
}
268+
}
269+
$displayDeprecations($deprecations);
270+
if ($isFailing || DeprecationErrorHandler::MODE_WEAK !== $mode && $mode < $deprecations['unsilencedCount'] + $deprecations['remainingCount'] + $deprecations['otherCount']) {
271+
exit(1);
272+
}
273+
});
253274
});
254275
}
255276
}

src/Symfony/Bridge/PhpUnit/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

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/AddCacheWarmerPassTest.php

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,57 +24,43 @@ class AddCacheWarmerPassTest extends TestCase
2424
public function testThatCacheWarmersAreProcessedInPriorityOrder()
2525
{
2626
$container = new ContainerBuilder();
27-
28-
$definition = $container->register('cache_warmer')->addArgument(null);
27+
$cacheWarmerDefinition = $container->register('cache_warmer')->addArgument(array());
2928
$container->register('my_cache_warmer_service1')->addTag('kernel.cache_warmer', array('priority' => 100));
3029
$container->register('my_cache_warmer_service2')->addTag('kernel.cache_warmer', array('priority' => 200));
3130
$container->register('my_cache_warmer_service3')->addTag('kernel.cache_warmer');
3231

3332
$addCacheWarmerPass = new AddCacheWarmerPass();
3433
$addCacheWarmerPass->process($container);
3534

36-
$expected = array(
37-
new Reference('my_cache_warmer_service2'),
38-
new Reference('my_cache_warmer_service1'),
39-
new Reference('my_cache_warmer_service3'),
35+
$this->assertEquals(
36+
array(
37+
new Reference('my_cache_warmer_service2'),
38+
new Reference('my_cache_warmer_service1'),
39+
new Reference('my_cache_warmer_service3'),
40+
),
41+
$cacheWarmerDefinition->getArgument(0)
4042
);
41-
$this->assertEquals($expected, $definition->getArgument(0));
4243
}
4344

4445
public function testThatCompilerPassIsIgnoredIfThereIsNoCacheWarmerDefinition()
4546
{
46-
$definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
47-
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('hasDefinition', 'findTaggedServiceIds', 'getDefinition'))->getMock();
48-
49-
$container->expects($this->never())->method('findTaggedServiceIds');
50-
$container->expects($this->never())->method('getDefinition');
51-
$container->expects($this->atLeastOnce())
52-
->method('hasDefinition')
53-
->with('cache_warmer')
54-
->will($this->returnValue(false));
55-
$definition->expects($this->never())->method('replaceArgument');
47+
$container = new ContainerBuilder();
5648

5749
$addCacheWarmerPass = new AddCacheWarmerPass();
5850
$addCacheWarmerPass->process($container);
51+
52+
// we just check that the pass does not break if no cache warmer is registered
53+
$this->addToAssertionCount(1);
5954
}
6055

6156
public function testThatCacheWarmersMightBeNotDefined()
6257
{
63-
$definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
64-
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('hasDefinition', 'findTaggedServiceIds', 'getDefinition'))->getMock();
65-
66-
$container->expects($this->atLeastOnce())
67-
->method('findTaggedServiceIds')
68-
->will($this->returnValue(array()));
69-
$container->expects($this->never())->method('getDefinition');
70-
$container->expects($this->atLeastOnce())
71-
->method('hasDefinition')
72-
->with('cache_warmer')
73-
->will($this->returnValue(true));
74-
75-
$definition->expects($this->never())->method('replaceArgument');
58+
$container = new ContainerBuilder();
59+
$cacheWarmerDefinition = $container->register('cache_warmer')->addArgument(array());
7660

7761
$addCacheWarmerPass = new AddCacheWarmerPass();
7862
$addCacheWarmerPass->process($container);
63+
64+
$this->assertSame(array(), $cacheWarmerDefinition->getArgument(0));
7965
}
8066
}

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/AddConstraintValidatorsPassTest.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,10 @@ public function testAbstractConstraintValidator()
6666

6767
public function testThatCompilerPassIsIgnoredIfThereIsNoConstraintValidatorFactoryDefinition()
6868
{
69-
$definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
70-
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('hasDefinition', 'findTaggedServiceIds', 'getDefinition'))->getMock();
71-
72-
$container->expects($this->never())->method('findTaggedServiceIds');
73-
$container->expects($this->never())->method('getDefinition');
74-
$container->expects($this->atLeastOnce())
75-
->method('hasDefinition')
76-
->with('validator.validator_factory')
77-
->will($this->returnValue(false));
78-
$definition->expects($this->never())->method('replaceArgument');
79-
8069
$addConstraintValidatorsPass = new AddConstraintValidatorsPass();
81-
$addConstraintValidatorsPass->process($container);
70+
$addConstraintValidatorsPass->process(new ContainerBuilder());
71+
72+
// we just check that the pass does not fail if no constraint validator factory is registered
73+
$this->addToAssertionCount(1);
8274
}
8375
}

0 commit comments

Comments
 (0)