From 5ba55f0cf287c583019bbb731ad98e04a14da972 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Wed, 8 Mar 2017 20:28:33 +0100 Subject: [PATCH] Move config exception to dedicated classes with proper namespace --- application/config/ConfigManager.php | 36 ++----------------- .../exception/MissingFieldConfigException.php | 23 ++++++++++++ .../exception/UnauthorizedConfigException.php | 18 ++++++++++ tests/config/ConfigManagerTest.php | 2 +- 4 files changed, 45 insertions(+), 34 deletions(-) create mode 100644 application/config/exception/MissingFieldConfigException.php create mode 100644 application/config/exception/UnauthorizedConfigException.php diff --git a/application/config/ConfigManager.php b/application/config/ConfigManager.php index 679a75b3..f2097410 100644 --- a/application/config/ConfigManager.php +++ b/application/config/ConfigManager.php @@ -1,6 +1,9 @@ configIO = $configIO; } } - -/** - * Exception used if a mandatory field is missing in given configuration. - */ -class MissingFieldConfigException extends \Exception -{ - public $field; - - /** - * Construct exception. - * - * @param string $field field name missing. - */ - public function __construct($field) - { - $this->field = $field; - $this->message = 'Configuration value is required for '. $this->field; - } -} - -/** - * Exception used if an unauthorized attempt to edit configuration has been made. - */ -class UnauthorizedConfigException extends \Exception -{ - /** - * Construct exception. - */ - public function __construct() - { - $this->message = 'You are not authorized to alter config.'; - } -} diff --git a/application/config/exception/MissingFieldConfigException.php b/application/config/exception/MissingFieldConfigException.php new file mode 100644 index 00000000..6346c6a9 --- /dev/null +++ b/application/config/exception/MissingFieldConfigException.php @@ -0,0 +1,23 @@ +field = $field; + $this->message = 'Configuration value is required for '. $this->field; + } +} diff --git a/application/config/exception/UnauthorizedConfigException.php b/application/config/exception/UnauthorizedConfigException.php new file mode 100644 index 00000000..79672c1b --- /dev/null +++ b/application/config/exception/UnauthorizedConfigException.php @@ -0,0 +1,18 @@ +message = 'You are not authorized to alter config.'; + } +} diff --git a/tests/config/ConfigManagerTest.php b/tests/config/ConfigManagerTest.php index b81be5b6..1ec447b2 100644 --- a/tests/config/ConfigManagerTest.php +++ b/tests/config/ConfigManagerTest.php @@ -106,7 +106,7 @@ public function testSetArrayKey() /** * Try to write the config without mandatory parameter (e.g. 'login'). * - * @expectedException Shaarli\Config\MissingFieldConfigException + * @expectedException Shaarli\Config\Exception\MissingFieldConfigException */ public function testWriteMissingParameter() {