From 43475f3387565c06ec74fefa7c7149c65852c612 Mon Sep 17 00:00:00 2001 From: Philip Ardery Date: Tue, 22 May 2018 09:25:07 -0700 Subject: [PATCH] Making PhpUnitBridge exeption that silences deprecation warnings when fetching private services from within tests more specific to check that the source class that called the deprecated code extends KernelTestCase instead of PhpUnit's base TestCase. --- src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php index f614ac99001b7..29b09b6df332c 100644 --- a/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php +++ b/src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php @@ -123,12 +123,13 @@ public static function register($mode = 0) // triggered deprecation notice; and the fourth event (index 3) // represents the action that called the deprecated code. In the // scenario that we want to suppress, the 4th event will be an - // object instance of \PHPUnit\Framework\TestCase. + // extension of Symfony\Bundle\FrameworkBundle\Test\KernelTestCase. if (isset($trace[3]['object'])) { $isPrivateServiceNotice = false !== strpos($msg, ' service is private, '); $isNoticeForContainerGetHasUsage = 'Symfony\Component\DependencyInjection\Container' === $trace[2]['class'] && in_array($trace[2]['function'], array('get', 'has')); - $noticeWasTriggeredByPhpUnitTest = $trace[3]['object'] instanceof \PHPUnit\Framework\TestCase; - if ($isPrivateServiceNotice && $isNoticeForContainerGetHasUsage && $noticeWasTriggeredByPhpUnitTest) { + $kernelTestCaseClass = 'Symfony\\Bundle\\FrameworkBundle\\Test\\KernelTestCase'; + $noticeWasTriggeredByKernelTestCase = $trace[3]['object'] instanceof $kernelTestCaseClass; + if ($isPrivateServiceNotice && $isNoticeForContainerGetHasUsage && $noticeWasTriggeredByKernelTestCase) { return false; } }