ExpectDeprecationTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace Drupal\Tests;
  3. use Drupal\Tests\Traits\ExpectDeprecationTrait;
  4. /**
  5. * @coversDefaultClass \Drupal\Tests\Traits\ExpectDeprecationTrait
  6. *
  7. * @group Test
  8. * @group legacy
  9. */
  10. class ExpectDeprecationTest extends UnitTestCase {
  11. use ExpectDeprecationTrait;
  12. /**
  13. * @covers ::addExpectedDeprecationMessage
  14. */
  15. public function testExpectDeprecation() {
  16. $this->addExpectedDeprecationMessage('Test deprecation');
  17. @trigger_error('Test deprecation', E_USER_DEPRECATED);
  18. }
  19. /**
  20. * @covers ::addExpectedDeprecationMessage
  21. * @runInSeparateProcess
  22. * @preserveGlobalState disabled
  23. */
  24. public function testExpectDeprecationInIsolation() {
  25. $this->addExpectedDeprecationMessage('Test isolated deprecation');
  26. $this->addExpectedDeprecationMessage('Test isolated deprecation2');
  27. @trigger_error('Test isolated deprecation', E_USER_DEPRECATED);
  28. @trigger_error('Test isolated deprecation2', E_USER_DEPRECATED);
  29. }
  30. /**
  31. * @covers ::expectDeprecation
  32. *
  33. * @todo the expectedDeprecation annotation does not work if tests are marked
  34. * skipped.
  35. * @see https://github.com/symfony/symfony/pull/25757
  36. */
  37. public function testDeprecatedExpectDeprecation() {
  38. $this->addExpectedDeprecationMessage('ExpectDeprecationTrait::expectDeprecation is deprecated in drupal:8.8.5 and is removed from drupal:9.0.0. Use ::addExpectedDeprecationMessage() instead. See https://www.drupal.org/node/3106024');
  39. $this->expectDeprecation('Test deprecated expectDeprecation');
  40. @trigger_error('Test deprecated expectDeprecation', E_USER_DEPRECATED);
  41. }
  42. }