AssertLegacyTrait.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace Drupal\KernelTests;
  3. /**
  4. * Translates Simpletest assertion methods to PHPUnit.
  5. *
  6. * Protected methods are custom. Public static methods override methods of
  7. * \PHPUnit\Framework\Assert.
  8. *
  9. * Deprecated Scheduled for removal in Drupal 10.0.0. Use PHPUnit's native
  10. * assert methods instead.
  11. *
  12. * @todo https://www.drupal.org/project/drupal/issues/3031580 Note that
  13. * deprecations in this file do not use the @ symbol in Drupal 8 because this
  14. * will be removed in Drupal 10.0.0.
  15. */
  16. trait AssertLegacyTrait {
  17. /**
  18. * @see \Drupal\simpletest\TestBase::assert()
  19. *
  20. * Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertTrue()
  21. * instead.
  22. */
  23. protected function assert($actual, $message = '') {
  24. parent::assertTrue((bool) $actual, $message);
  25. }
  26. /**
  27. * @see \Drupal\simpletest\TestBase::assertEqual()
  28. *
  29. * Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertEquals()
  30. * instead.
  31. */
  32. protected function assertEqual($actual, $expected, $message = '') {
  33. $this->assertEquals($expected, $actual, (string) $message);
  34. }
  35. /**
  36. * @see \Drupal\simpletest\TestBase::assertNotEqual()
  37. *
  38. * Deprecated Scheduled for removal in Drupal 10.0.0. Use
  39. * self::assertNotEquals() instead.
  40. */
  41. protected function assertNotEqual($actual, $expected, $message = '') {
  42. $this->assertNotEquals($expected, $actual, (string) $message);
  43. }
  44. /**
  45. * @see \Drupal\simpletest\TestBase::assertIdentical()
  46. *
  47. * Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertSame()
  48. * instead.
  49. */
  50. protected function assertIdentical($actual, $expected, $message = '') {
  51. $this->assertSame($expected, $actual, (string) $message);
  52. }
  53. /**
  54. * @see \Drupal\simpletest\TestBase::assertNotIdentical()
  55. *
  56. * Deprecated Scheduled for removal in Drupal 10.0.0. Use
  57. * self::assertNotSame() instead.
  58. */
  59. protected function assertNotIdentical($actual, $expected, $message = '') {
  60. $this->assertNotSame($expected, $actual, (string) $message);
  61. }
  62. /**
  63. * @see \Drupal\simpletest\TestBase::assertIdenticalObject()
  64. *
  65. * Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertEquals()
  66. * instead.
  67. */
  68. protected function assertIdenticalObject($actual, $expected, $message = '') {
  69. // Note: ::assertSame checks whether its the same object. ::assertEquals
  70. // though compares
  71. $this->assertEquals($expected, $actual, (string) $message);
  72. }
  73. /**
  74. * @see \Drupal\simpletest\TestBase::pass()
  75. *
  76. * Deprecated Scheduled for removal in Drupal 10.0.0. Use self::assertTrue()
  77. * instead.
  78. */
  79. protected function pass($message) {
  80. $this->assertTrue(TRUE, $message);
  81. }
  82. /**
  83. * @see \Drupal\simpletest\TestBase::verbose()
  84. */
  85. protected function verbose($message) {
  86. if (in_array('--debug', $_SERVER['argv'], TRUE)) {
  87. // Write directly to STDOUT to not produce unexpected test output.
  88. // The STDOUT stream does not obey output buffering.
  89. fwrite(STDOUT, $message . "\n");
  90. }
  91. }
  92. }