ExpectDeprecationTraitBeforeV8_4.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bridge\PhpUnit\Legacy;
  11. /**
  12. * @internal, use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait instead.
  13. */
  14. trait ExpectDeprecationTraitBeforeV8_4
  15. {
  16. /**
  17. * @param string $message
  18. *
  19. * @return void
  20. */
  21. protected function expectDeprecation($message)
  22. {
  23. // Expected deprecations set by isolated tests need to be written to a file
  24. // so that the test running process can take account of them.
  25. if ($file = getenv('SYMFONY_EXPECTED_DEPRECATIONS_SERIALIZE')) {
  26. $this->getTestResultObject()->beStrictAboutTestsThatDoNotTestAnything(false);
  27. $expectedDeprecations = file_get_contents($file);
  28. if ($expectedDeprecations) {
  29. $expectedDeprecations = array_merge(unserialize($expectedDeprecations), [$message]);
  30. } else {
  31. $expectedDeprecations = [$message];
  32. }
  33. file_put_contents($file, serialize($expectedDeprecations));
  34. return;
  35. }
  36. if (!SymfonyTestsListenerTrait::$previousErrorHandler) {
  37. SymfonyTestsListenerTrait::$previousErrorHandler = set_error_handler([SymfonyTestsListenerTrait::class, 'handleError']);
  38. }
  39. SymfonyTestsListenerTrait::$expectedDeprecations[] = $message;
  40. }
  41. }