Merge pull request #794 from ArthurHoaro/hotfix/namespace

Move config exception to dedicated classes with proper namespace
This commit is contained in:
ArthurHoaro 2017-03-09 19:45:52 +01:00 committed by GitHub
commit 16a2ef6b5a
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()
{