Unverified Commit 474b03c7 authored by alexpott's avatar alexpott

Issue #2696103 by Gabr1el, DerekCresswell, ashok.gharpankar, chOP, alexpott:...

Issue #2696103 by Gabr1el, DerekCresswell, ashok.gharpankar, chOP, alexpott: \Drupal\Core\Config\FileStorageFactory::getSync() should throw a more specific exception
parent 761dbfb3
<?php
namespace Drupal\Core\Config;
/**
* An exception thrown when the config sync directory is not defined.
*/
class ConfigDirectoryNotDefinedException extends ConfigException {}
......@@ -14,16 +14,14 @@ class FileStorageFactory {
*
* @return \Drupal\Core\Config\FileStorage FileStorage
*
* @throws \Exception
* @throws \Drupal\Core\Config\ConfigDirectoryNotDefinedException
* In case the sync directory does not exist or is not defined in
* $settings['config_sync_directory'].
*/
public static function getSync() {
$directory = Settings::get('config_sync_directory', FALSE);
if ($directory === FALSE) {
// @todo: throw a more specific exception.
// @see https://www.drupal.org/node/2696103
throw new \Exception('The config sync directory is not defined in $settings["config_sync_directory"]');
throw new ConfigDirectoryNotDefinedException('The config sync directory is not defined in $settings["config_sync_directory"]');
}
return new FileStorage($directory);
}
......
......@@ -2,6 +2,7 @@
namespace Drupal\KernelTests\Core\Config;
use Drupal\Core\Config\ConfigDirectoryNotDefinedException;
use Drupal\Core\Config\FileStorage;
use Drupal\Core\Config\FileStorageFactory;
use Drupal\Core\Site\Settings;
......@@ -34,13 +35,9 @@ public function testGetSync() {
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());
}
$this->expectException(ConfigDirectoryNotDefinedException::class);
$this->expectExceptionMessage('The config sync directory is not defined in $settings["config_sync_directory"]');
FileStorageFactory::getSync();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment