Move config exception to dedicated classes with proper namespace

This commit is contained in:
ArthurHoaro 2017-03-08 20:28:33 +01:00
parent 9c5daad19c
commit 5ba55f0cf2
4 changed files with 45 additions and 34 deletions

View File

@ -1,6 +1,9 @@
<?php
namespace Shaarli\Config;
use Shaarli\Config\Exception\MissingFieldConfigException;
use Shaarli\Config\Exception\UnauthorizedConfigException;
/**
* Class ConfigManager
*
@ -358,36 +361,3 @@ class ConfigManager
$this->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.';
}
}

View File

@ -0,0 +1,23 @@
<?php
namespace Shaarli\Config\Exception;
/**
* 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;
}
}

View File

@ -0,0 +1,18 @@
<?php
namespace Shaarli\Config\Exception;
/**
* 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.';
}
}

View File

@ -106,7 +106,7 @@ class ConfigManagerTest extends \PHPUnit_Framework_TestCase
/**
* Try to write the config without mandatory parameter (e.g. 'login').
*
* @expectedException Shaarli\Config\MissingFieldConfigException
* @expectedException Shaarli\Config\Exception\MissingFieldConfigException
*/
public function testWriteMissingParameter()
{