You are here

public function ShutdownFunctionTest::testShutdownFunctionInShutdownFunction in Drupal 9

Same name and namespace in other branches
  1. 10 core/tests/Drupal/KernelTests/Core/Bootstrap/ShutdownFunctionTest.php \Drupal\KernelTests\Core\Bootstrap\ShutdownFunctionTest::testShutdownFunctionInShutdownFunction()

Tests that shutdown functions can be added by other shutdown functions.

File

core/tests/Drupal/KernelTests/Core/Bootstrap/ShutdownFunctionTest.php, line 31

Class

ShutdownFunctionTest
Tests.

Namespace

Drupal\KernelTests\Core\Bootstrap

Code

public function testShutdownFunctionInShutdownFunction() {

  // Ensure there are no shutdown functions registered before starting the
  // test.
  $this
    ->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());
}