diff --git a/core/tests/Drupal/KernelTests/Core/Bootstrap/ShutdownFunctionTest.php b/core/tests/Drupal/KernelTests/Core/Bootstrap/ShutdownFunctionTest.php new file mode 100644 index 000000000000..e8d7dad85ff5 --- /dev/null +++ b/core/tests/Drupal/KernelTests/Core/Bootstrap/ShutdownFunctionTest.php @@ -0,0 +1,64 @@ +assertEmpty(drupal_register_shutdown_function()); + // Register a shutdown function that, when called, will register another + // shutdown function. + drupal_register_shutdown_function([$this, 'shutdownOne']); + $this->assertCount(1, drupal_register_shutdown_function()); + + // Simulate the Drupal shutdown. + _drupal_shutdown_function(); + + // Test that the expected functions are called. + $this->assertTrue($this->shutDownOneCalled); + $this->assertTrue($this->shutDownTwoCalled); + $this->assertCount(2, drupal_register_shutdown_function()); + } + + /** + * Tests shutdown functions by registering another shutdown function. + */ + public function shutdownOne() { + drupal_register_shutdown_function([$this, 'shutdownTwo']); + $this->shutDownOneCalled = TRUE; + } + + /** + * Tests shutdown functions by being registered during shutdown. + */ + public function shutdownTwo() { + $this->shutDownTwoCalled = TRUE; + } + +}