testing file config, pass

master
Guillermo Dev 7 years ago
parent 40d96a8911
commit db326b1e3c

@ -0,0 +1,45 @@
<?php
/**
* 'odbc:Driver=FreeTDS;
* Server=192.168.0.8;
* Port=1218;
* Database=netbiblio;
* TDS_Version=7.4;
* ClientCharset=UTF-8'* 'alcoda', 'alcodaonly'
*/
return array(
'db' => array(
'driver' => 'FreeTDS',
'server' => '192.168.0.8',
'port' => '1218',
'username' => 'alcoda',
'password' => 'alcodaonly',
'name' => 'netbiblio',
),
'solr' => array(
'server' => '212.147.56.162',
'port' => '8983',
'username' => '',
'password' => '',
'path' => 'solr/',
'result_count' => 10,
),
'log' => array(
'file' => '/var/www/webservice/logs/log.txt',
'format' => '%ip% - [%date%] - %status% %error% - %time% - %func%',
// The greater the verbosity, the more is displayed
// 0 : no log at all
// 1 : log summary
// 2 : log response
'verbosity' => 1,
),
'session' => array(
'save_path' => ''
),
'checkfile_url' => 'http://medias.bibliothequesonore.ch/checkfile.php?',
'checkfile_url_old' => 'http://fichiers.bibliothequesonore.ch/checkfile.php?',
'netbiblio_worker_id' => 45,
'www_employee_id' => 45,
'www_library_id' => 2,
);

Binary file not shown.

@ -8,6 +8,11 @@ class Configuration {
*/
private static $instance = null;
/**
* @var
*/
private static $customConfigFilePath;
/**
* ! WARNING !
*
@ -23,8 +28,9 @@ class Configuration {
*/
private $values = array();
private $customConfigFilename = 'configuration.local.php';
/**
*
*/
private function __construct()
{
if (!isset($this->values['session'])) {
@ -34,27 +40,47 @@ class Configuration {
if (!isset($this->values['session']['save_path'])) {
$this->values['session']['save_path'] = session_save_path();
}
if (file_exists(self::getConfigFilePath())) {
$this->loadConfigFromFile();
}
}
/**
* The path to the file including file name
* @param string $filePath
* @return void
*/
public static function setConfigFilePath($filePath)
{
if (!file_exists($filePath)) {
throw new \RuntimeException("The file path $filePath, does not exist");
}
self::$customConfigFilePath = $filePath;
}
/**
*
* @return String
*/
public function getCustomConfigFilePath()
public static function getConfigFilePath()
{
return realpath(dirname(__FILE__) . '/../../../../../config/') . $this->customConfigFilename;
if (null === self::$customConfigFilePath) {
self::$customConfigFilePath = realpath(dirname(__FILE__) . '/../../../../../config/configuration.local.php');
}
return self::$customConfigFilePath;
}
/**
* @return array
* @throws \RuntimeException
*/
public function getCustomConfigFromFile()
public function getConfigFromFile()
{
if (!file_exists($this->getCustomConfigFilePath())) {
throw new \RuntimeException("The file : {$this->getCustomConfigFilePath()} does not exist");
if (!file_exists(self::getConfigFilePath())) {
throw new \RuntimeException("The file : {self::getConfigFilePath()} does not exist");
}
return include $this->getCustomConfigFilePath();
return include self::getConfigFilePath();
}
/**
@ -62,9 +88,9 @@ class Configuration {
* @return void
* @throws \RuntimeException
*/
public function loadCustomConfigFromFile()
public function loadConfigFromFile()
{
$this->setCustomConfig($this->getCustomConfigFromFile());
$this->setCustomConfig($this->getConfigFromFile());
}
/**

@ -16,10 +16,12 @@ class ConfigurationTest extends TestCase
);
protected $defaultConfig;
protected $dummyConfigFilePath;
public function setUp()
{
$this->defaultConfig = array('session' => array('save_path' => session_save_path()));
$this->dummyConfigFilePath = realpath(dirname(__FILE__) . '/../../config/configuration.local.php');
}
public function testConfigurationInstanceIsTheSame()
@ -113,4 +115,17 @@ class ConfigurationTest extends TestCase
Configuration::getInstance()->setCustomConfig($this->testConfig);
$this->assertSame(Configuration::get(), $this->testConfig);
}
public function testDummyConfigFileExists()
{
$this->assertEquals(file_exists($this->dummyConfigFilePath), true);
}
public function testFileCustomConfigGetsLoadedIfFileExists()
{
$configPriorToFileLoading = Configuration::get();
Configuration::setConfigFilePath($this->dummyConfigFilePath);
Configuration::getInstance()->loadConfigFromFile();
$this->assertSame(Configuration::get(), array_replace_recursive($this->testConfig, include $this->dummyConfigFilePath));
}
}

Loading…
Cancel
Save