Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[PhpUnitBridge] Making private service deprecation warning supressor more strict #27342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/Symfony/Bridge/PhpUnit/DeprecationErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this var should be removed, instanceof works better with a symbol than with a string

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(and a use statement be used instead)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should definitely be WebTestCase at least, as KernelTestCase only allows to use $kernel->getContainer()->get('private_something') in 3.x, which is always a valid deprecation

$noticeWasTriggeredByKernelTestCase = $trace[3]['object'] instanceof $kernelTestCaseClass;
if ($isPrivateServiceNotice && $isNoticeForContainerGetHasUsage && $noticeWasTriggeredByKernelTestCase) {
return false;
}
}
Expand Down