class DestructableServiceTest
Same name and namespace in other branches
- 11.x core/tests/Drupal/FunctionalTests/HttpKernel/DestructableServiceTest.php \Drupal\FunctionalTests\HttpKernel\DestructableServiceTest
- 10 core/tests/Drupal/FunctionalTests/HttpKernel/DestructableServiceTest.php \Drupal\FunctionalTests\HttpKernel\DestructableServiceTest
Tests invocation of services performing deferred tasks after response flush.
Attributes
#[Group('Http')]
#[RunTestsInSeparateProcesses]
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Tests\DrupalTestCaseTrait, \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\PhpUnitCompatibilityTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\FunctionalTests\HttpKernel\DestructableServiceTest extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of DestructableServiceTest
See also
\Drupal\Core\DestructableInterface
File
-
core/
tests/ Drupal/ FunctionalTests/ HttpKernel/ DestructableServiceTest.php, line 18
Namespace
Drupal\FunctionalTests\HttpKernelView source
class DestructableServiceTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'system',
'destructable_test',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
public function testDestructableServiceExecutionOrder() : void {
$file_system = $this->container
->get('file_system');
assert($file_system instanceof FileSystemInterface);
$semaphore = $file_system->tempnam($file_system->getTempDirectory(), 'destructable_semaphore');
$this->drupalGet(Url::fromRoute('destructable', [], [
'query' => [
'semaphore' => $semaphore,
],
]));
// This should be false as the response should flush before running the
// test service.
$this->assertEmpty(file_get_contents($semaphore), 'Destructable service did not run when response flushed to client.');
// The destructable service will sleep for 3 seconds, then run.
// To ensure no race conditions on slow test runners, wait another 3s.
sleep(6);
$this->assertTrue(file_get_contents($semaphore) === 'ran', 'Destructable service did run.');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.