DrupalFlushAllCachesInInstallerTest.php in Drupal 9
File
core/tests/Drupal/FunctionalTests/Installer/DrupalFlushAllCachesInInstallerTest.php
View source
<?php
namespace Drupal\FunctionalTests\Installer;
use Drupal\Core\Serialization\Yaml;
use Drupal\Tests\BrowserTestBase;
class DrupalFlushAllCachesInInstallerTest extends BrowserTestBase {
protected $defaultTheme = 'stark';
protected $profile = 'cache_flush_test';
protected function prepareEnvironment() {
parent::prepareEnvironment();
$info = [
'type' => 'profile',
'core_version_requirement' => '*',
'name' => 'Cache flush test',
'install' => [
'language',
],
];
$path = $this->siteDirectory . '/profiles/cache_flush_test';
mkdir($path, 0777, TRUE);
file_put_contents("{$path}/cache_flush_test.info.yml", Yaml::encode($info));
$php_code = <<<EOF
<?php
function cache_flush_test_install() {
// Note it is bad practice to call this method during hook_install() as it
// results in an additional expensive container rebuild.
drupal_flush_all_caches();
// Ensure services are available after calling drupal_flush_all_caches().
\\Drupal::state()->set('cache_flush_test', \\Drupal::hasService('language_negotiator'));
}
EOF;
file_put_contents("{$path}/cache_flush_test.install", $php_code);
}
public function testInstalled() {
$this
->assertTrue(\Drupal::state()
->get('cache_flush_test'));
}
}