FileStorageFactoryTest.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace Drupal\KernelTests\Core\Config;
  3. use Drupal\Core\Config\FileStorage;
  4. use Drupal\Core\Config\FileStorageFactory;
  5. use Drupal\Core\Site\Settings;
  6. use Drupal\KernelTests\KernelTestBase;
  7. /**
  8. * @coversDefaultClass \Drupal\Core\Config\FileStorageFactory
  9. * @group config
  10. */
  11. class FileStorageFactoryTest extends KernelTestBase {
  12. /**
  13. * @covers ::getSync
  14. */
  15. public function testGetSync() {
  16. // Write some random data to the sync storage.
  17. $name = $this->randomMachineName();
  18. $data = (array) $this->getRandomGenerator()->object();
  19. $storage = new FileStorage(Settings::get('config_sync_directory'));
  20. $storage->write($name, $data);
  21. // Get the sync storage and read from it.
  22. $sync = FileStorageFactory::getSync();
  23. $this->assertEquals($data, $sync->read($name));
  24. // Unset the sync directory setting.
  25. $settings = Settings::getInstance() ? Settings::getAll() : [];
  26. unset($settings['config_sync_directory']);
  27. new Settings($settings);
  28. // On an empty settings there is an exception thrown.
  29. try {
  30. FileStorageFactory::getSync();
  31. $this->fail("The exception was not thrown.");
  32. }
  33. catch (\Exception $exception) {
  34. $this->assertEquals('The config sync directory is not defined in $settings["config_sync_directory"]', $exception->getMessage());
  35. }
  36. }
  37. }