class FileStorageTest
Same name in this branch
- 9 core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php \Drupal\Tests\Component\PhpStorage\FileStorageTest
Same name and namespace in other branches
- 11.x core/tests/Drupal/KernelTests/Core/Config/Storage/FileStorageTest.php \Drupal\KernelTests\Core\Config\Storage\FileStorageTest
- 11.x core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php \Drupal\Tests\Component\PhpStorage\FileStorageTest
- 10 core/tests/Drupal/KernelTests/Core/Config/Storage/FileStorageTest.php \Drupal\KernelTests\Core\Config\Storage\FileStorageTest
- 10 core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php \Drupal\Tests\Component\PhpStorage\FileStorageTest
Tests FileStorage operations.
@group config
Hierarchy
- class \Drupal\KernelTests\KernelTestBase extends \Drupal\Core\DependencyInjection\ServiceProviderInterface uses \Drupal\KernelTests\AssertLegacyTrait, \Drupal\KernelTests\AssertContentTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\ExtensionListTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\KernelTests\Core\Config\Storage\ConfigStorageTestBase implements \Drupal\KernelTests\KernelTestBase
- class \Drupal\KernelTests\Core\Config\Storage\FileStorageTest implements \Drupal\KernelTests\Core\Config\Storage\ConfigStorageTestBase
- class \Drupal\KernelTests\Core\Config\Storage\ConfigStorageTestBase implements \Drupal\KernelTests\KernelTestBase
Expanded class hierarchy of FileStorageTest
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Config/ Storage/ FileStorageTest.php, line 15
Namespace
Drupal\KernelTests\Core\Config\StorageView source
class FileStorageTest extends ConfigStorageTestBase {
/**
* A directory to store configuration in.
*
* @var string
*/
protected $directory;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
// Create a directory.
$this->directory = PublicStream::basePath() . '/config';
$this->storage = new FileStorage($this->directory);
$this->invalidStorage = new FileStorage($this->directory . '/nonexisting');
// FileStorage::listAll() requires other configuration data to exist.
$this->storage
->write('system.performance', $this->config('system.performance')
->get());
$this->storage
->write('core.extension', [
'module' => [],
]);
}
protected function read($name) {
$data = file_get_contents($this->storage
->getFilePath($name));
return Yaml::decode($data);
}
protected function insert($name, $data) {
file_put_contents($this->storage
->getFilePath($name), $data);
}
protected function update($name, $data) {
file_put_contents($this->storage
->getFilePath($name), $data);
}
protected function delete($name) {
unlink($this->storage
->getFilePath($name));
}
/**
* Tests the FileStorage::listAll method with a relative and absolute path.
*/
public function testlistAll() {
$expected_files = [
'core.extension',
'system.performance',
];
$config_files = $this->storage
->listAll();
$this->assertSame($expected_files, $config_files, 'Relative path, two config files found.');
// @todo https://www.drupal.org/node/2666954 FileStorage::listAll() is
// case-sensitive. However, \Drupal\Core\Config\DatabaseStorage::listAll()
// is case-insensitive.
$this->assertSame([
'system.performance',
], $this->storage
->listAll('system'), 'The FileStorage::listAll() with prefix works.');
$this->assertSame([], $this->storage
->listAll('System'), 'The FileStorage::listAll() is case sensitive.');
}
/**
* Tests UnsupportedDataTypeConfigException.
*/
public function testUnsupportedDataTypeConfigException() {
$name = 'core.extension';
$path = $this->storage
->getFilePath($name);
$this->expectException(UnsupportedDataTypeConfigException::class);
$this->expectExceptionMessageMatches("@Invalid data type in config {$name}, found in file {$path}: @");
file_put_contents($path, PHP_EOL . 'foo : @bar', FILE_APPEND);
$this->storage
->read($name);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.