KernelTestBaseShutdownTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace Drupal\KernelTests;
  3. /**
  4. * @coversDefaultClass \Drupal\KernelTests\KernelTestBase
  5. *
  6. * @group PHPUnit
  7. * @group Test
  8. * @group KernelTests
  9. */
  10. class KernelTestBaseShutdownTest extends KernelTestBase {
  11. /**
  12. * Indicates which shutdown functions are expected to be called.
  13. *
  14. * @var array
  15. */
  16. protected $expectedShutdownCalled;
  17. /**
  18. * Indicates which shutdown functions have been called.
  19. *
  20. * @var array
  21. */
  22. protected static $shutdownCalled;
  23. /**
  24. * {@inheritdoc}
  25. */
  26. protected function setUp() {
  27. // Initialize static variable prior to testing.
  28. self::$shutdownCalled = [];
  29. parent::setUp();
  30. }
  31. /**
  32. * @covers ::assertPostConditions
  33. */
  34. public function testShutdownFunction() {
  35. $this->expectedShutdownCalled = ['shutdownFunction', 'shutdownFunction2'];
  36. drupal_register_shutdown_function([$this, 'shutdownFunction']);
  37. }
  38. /**
  39. * @covers ::assertPostConditions
  40. */
  41. public function testNoShutdownFunction() {
  42. $this->expectedShutdownCalled = [];
  43. }
  44. /**
  45. * Registers that this shutdown function has been called.
  46. */
  47. public function shutdownFunction() {
  48. self::$shutdownCalled[] = 'shutdownFunction';
  49. drupal_register_shutdown_function([$this, 'shutdownFunction2']);
  50. }
  51. /**
  52. * Registers that this shutdown function has been called.
  53. */
  54. public function shutdownFunction2() {
  55. self::$shutdownCalled[] = 'shutdownFunction2';
  56. }
  57. /**
  58. * {@inheritdoc}
  59. */
  60. protected function assertPostConditions() {
  61. parent::assertPostConditions();
  62. $this->assertSame($this->expectedShutdownCalled, self::$shutdownCalled);
  63. }
  64. }