Allow the configuration file to be defined by a PHP constant for phpunit

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1599 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2014-07-30 11:28:56 +00:00
parent 09e7559086
commit 725356dda0

View File

@@ -20,6 +20,14 @@ class config
/** Use the .php to protect the informations */ /** Use the .php to protect the informations */
public $confFile = "./datas/configuration.php"; public $confFile = "./datas/configuration.php";
/** The constructor can update the confFile variable if it is defined in a
constant */
public function __construct ()
{
if (defined("CONFIGFILE"))
$this->confFile = CONFIGFILE;
}
/** List all the parameters configurable in the software */ /** List all the parameters configurable in the software */
public function params () public function params ()
{ {
@@ -40,9 +48,13 @@ class config
"<?php\r\n\$conf = array ();\r\n") "<?php\r\n\$conf = array ();\r\n")
=== FALSE) === FALSE)
throw new Exception (sprintf ( throw new Exception (sprintf (
"No configuration file '%s' available and it can't be created", _("No configuration file '%s' available and it can't be created"),
$this->confFile)); $this->confFile));
} }
elseif (! is_readable ($this->confFile))
throw new Exception (sprintf (
_("The configuration file '%s' is not readable"),
$this->confFile));
$conf = array (); $conf = array ();
$rc = include ($this->confFile); $rc = include ($this->confFile);
if ($rc !== 1) if ($rc !== 1)
@@ -69,6 +81,10 @@ class config
"No configuration file '%s' available and it can't be created", "No configuration file '%s' available and it can't be created",
$this->confFile)); $this->confFile));
} }
elseif (! is_readable ($this->confFile))
throw new Exception (sprintf (
_("The configuration file '%s' is not readable"),
$this->confFile));
if (!is_writeable ($this->confFile)) if (!is_writeable ($this->confFile))
throw new Exception (sprintf ( throw new Exception (sprintf (
"Configuration file '%s' is write protected", "Configuration file '%s' is write protected",