function FileStorageFactoryTest::testGetSync

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Config/FileStorageFactoryTest.php \Drupal\KernelTests\Core\Config\FileStorageFactoryTest::testGetSync()
  2. 10 core/tests/Drupal/KernelTests/Core/Config/FileStorageFactoryTest.php \Drupal\KernelTests\Core\Config\FileStorageFactoryTest::testGetSync()
  3. 11.x core/tests/Drupal/KernelTests/Core/Config/FileStorageFactoryTest.php \Drupal\KernelTests\Core\Config\FileStorageFactoryTest::testGetSync()

@covers ::getSync

File

core/tests/Drupal/KernelTests/Core/Config/FileStorageFactoryTest.php, line 19

Class

FileStorageFactoryTest
@coversDefaultClass \Drupal\Core\Config\FileStorageFactory @group config

Namespace

Drupal\KernelTests\Core\Config

Code

public function testGetSync() {
    // Write some random data to the sync storage.
    $name = $this->randomMachineName();
    $data = (array) $this->getRandomGenerator()
        ->object();
    $storage = new FileStorage(Settings::get('config_sync_directory'));
    $storage->write($name, $data);
    // Get the sync storage and read from it.
    $sync = FileStorageFactory::getSync();
    $this->assertEquals($data, $sync->read($name));
    // Unset the sync directory setting.
    $settings = Settings::getInstance() ? Settings::getAll() : [];
    unset($settings['config_sync_directory']);
    new Settings($settings);
    // On an empty settings there is an exception thrown.
    try {
        FileStorageFactory::getSync();
        $this->fail("The exception was not thrown.");
    } catch (\Exception $exception) {
        $this->assertEquals('The config sync directory is not defined in $settings["config_sync_directory"]', $exception->getMessage());
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.