From 9a9c0f6142d5685c0ca9684825683faed5eaa788 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sun, 11 Feb 2018 22:40:17 +0100 Subject: [PATCH] [Bridge/PhpUnit] Fix tests by backporting #25997 to 3.4 --- src/Symfony/Bridge/PhpUnit/CHANGELOG.md | 2 ++ .../Bridge/PhpUnit/DeprecationErrorHandler.php | 11 +++++------ .../fake_vendor/acme/lib/deprecation_riddled.php | 2 ++ .../PhpUnit/Tests/DeprecationErrorHandler/weak.phpt | 1 - .../weak_vendors_on_vendor.phpt | 8 ++++---- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Symfony/Bridge/PhpUnit/CHANGELOG.md b/src/Symfony/Bridge/PhpUnit/CHANGELOG.md index 39ae3a881b..5c6ee47309 100644 --- a/src/Symfony/Bridge/PhpUnit/CHANGELOG.md +++ b/src/Symfony/Bridge/PhpUnit/CHANGELOG.md @@ -5,6 +5,8 @@ CHANGELOG ----- * added a `CoverageListener` to enhance the code coverage report + * all deprecations but those from tests marked with `@group legacy` are always + displayed when not in `weak` mode 3.3.0 ----- diff --git a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php index 90cea694c3..e14d218708 100644 --- a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php +++ b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php @@ -110,8 +110,7 @@ class DeprecationErrorHandler $trace = debug_backtrace(true); $group = 'other'; - $isVendor = false; - $isWeak = DeprecationErrorHandler::MODE_WEAK === $mode || (DeprecationErrorHandler::MODE_WEAK_VENDORS === $mode && $isVendor = $inVendors($file)); + $isVendor = DeprecationErrorHandler::MODE_WEAK_VENDORS === $mode && $inVendors($file); $i = count($trace); while (1 < $i && (!isset($trace[--$i]['class']) || ('ReflectionMethod' === $trace[$i]['class'] || 0 === strpos($trace[$i]['class'], 'PHPUnit_') || 0 === strpos($trace[$i]['class'], 'PHPUnit\\')))) { @@ -128,7 +127,7 @@ class DeprecationErrorHandler // \Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListenerTrait::endTest() // then we need to use the serialized information to determine // if the error has been triggered from vendor code. - $isWeak = DeprecationErrorHandler::MODE_WEAK === $mode || (DeprecationErrorHandler::MODE_WEAK_VENDORS === $mode && $isVendor = isset($parsedMsg['triggering_file']) && $inVendors($parsedMsg['triggering_file'])); + $isVendor = DeprecationErrorHandler::MODE_WEAK_VENDORS === $mode && isset($parsedMsg['triggering_file']) && $inVendors($parsedMsg['triggering_file']); } else { $class = isset($trace[$i]['object']) ? get_class($trace[$i]['object']) : $trace[$i]['class']; $method = $trace[$i]['function']; @@ -145,7 +144,7 @@ class DeprecationErrorHandler || in_array('legacy', $Test::getGroups($class, $method), true) ) { $group = 'legacy'; - } elseif (DeprecationErrorHandler::MODE_WEAK_VENDORS === $mode && $isVendor) { + } elseif ($isVendor) { $group = 'remaining vendor'; } else { $group = 'remaining'; @@ -165,13 +164,13 @@ class DeprecationErrorHandler exit(1); } - if ('legacy' !== $group && !$isWeak) { + if ('legacy' !== $group && DeprecationErrorHandler::MODE_WEAK !== $mode) { $ref = &$deprecations[$group][$msg]['count']; ++$ref; $ref = &$deprecations[$group][$msg][$class.'::'.$method]; ++$ref; } - } elseif (!$isWeak) { + } elseif (DeprecationErrorHandler::MODE_WEAK !== $mode) { $ref = &$deprecations[$group][$msg]['count']; ++$ref; } diff --git a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/fake_vendor/acme/lib/deprecation_riddled.php b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/fake_vendor/acme/lib/deprecation_riddled.php index 6f5123d4fe..16a58246d2 100644 --- a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/fake_vendor/acme/lib/deprecation_riddled.php +++ b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/fake_vendor/acme/lib/deprecation_riddled.php @@ -21,6 +21,8 @@ class FooTestCase { @trigger_error('silenced foo deprecation', E_USER_DEPRECATED); trigger_error('unsilenced foo deprecation', E_USER_DEPRECATED); + @trigger_error('silenced foo deprecation', E_USER_DEPRECATED); + trigger_error('unsilenced foo deprecation', E_USER_DEPRECATED); } public function testNonLegacyBar() diff --git a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/weak.phpt b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/weak.phpt index 9e78d96e70..8137a2ff44 100644 --- a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/weak.phpt +++ b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/weak.phpt @@ -37,4 +37,3 @@ Unsilenced deprecation notices (1) Legacy deprecation notices (1) Other deprecation notices (1) - diff --git a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/weak_vendors_on_vendor.phpt b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/weak_vendors_on_vendor.phpt index 67e5458a17..68e233df7d 100644 --- a/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/weak_vendors_on_vendor.phpt +++ b/src/Symfony/Bridge/PhpUnit/Tests/DeprecationErrorHandler/weak_vendors_on_vendor.phpt @@ -20,10 +20,10 @@ require __DIR__.'/fake_vendor/acme/lib/deprecation_riddled.php'; ?> --EXPECTF-- -Unsilenced deprecation notices (2) +Unsilenced deprecation notices (3) - 1x: unsilenced foo deprecation - 1x in FooTestCase::testLegacyFoo + 2x: unsilenced foo deprecation + 2x in FooTestCase::testLegacyFoo 1x: unsilenced bar deprecation 1x in FooTestCase::testNonLegacyBar @@ -33,7 +33,7 @@ Remaining vendor deprecation notices (1) 1x: silenced bar deprecation 1x in FooTestCase::testNonLegacyBar -Legacy deprecation notices (1) +Legacy deprecation notices (2) Other deprecation notices (1)