ExpectDeprecationTraitForV8_4.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 ExpectDeprecationTraitForV8_4
  15. {
  16. /**
  17. * @param string $message
  18. */
  19. public function expectDeprecation(): void
  20. {
  21. if (1 > \func_num_args() || !\is_string($message = func_get_arg(0))) {
  22. throw new \InvalidArgumentException(sprintf('The "%s()" method requires the string $message argument.', __FUNCTION__));
  23. }
  24. // Expected deprecations set by isolated tests need to be written to a file
  25. // so that the test running process can take account of them.
  26. if ($file = getenv('SYMFONY_EXPECTED_DEPRECATIONS_SERIALIZE')) {
  27. $this->getTestResultObject()->beStrictAboutTestsThatDoNotTestAnything(false);
  28. $expectedDeprecations = file_get_contents($file);
  29. if ($expectedDeprecations) {
  30. $expectedDeprecations = array_merge(unserialize($expectedDeprecations), [$message]);
  31. } else {
  32. $expectedDeprecations = [$message];
  33. }
  34. file_put_contents($file, serialize($expectedDeprecations));
  35. return;
  36. }
  37. if (!SymfonyTestsListenerTrait::$previousErrorHandler) {
  38. SymfonyTestsListenerTrait::$previousErrorHandler = set_error_handler([SymfonyTestsListenerTrait::class, 'handleError']);
  39. }
  40. SymfonyTestsListenerTrait::$expectedDeprecations[] = $message;
  41. }
  42. /**
  43. * @internal use expectDeprecation() instead
  44. */
  45. public function expectDeprecationMessage(string $message): void
  46. {
  47. throw new \BadMethodCallException(sprintf('The "%s()" method is not supported by Symfony\'s PHPUnit Bridge ExpectDeprecationTrait, pass the message to expectDeprecation() instead.', __FUNCTION__));
  48. }
  49. /**
  50. * @internal use expectDeprecation() instead
  51. */
  52. public function expectDeprecationMessageMatches(string $regularExpression): void
  53. {
  54. throw new \BadMethodCallException(sprintf('The "%s()" method is not supported by Symfony\'s PHPUnit Bridge ExpectDeprecationTrait.', __FUNCTION__));
  55. }
  56. }