From db326b1e3c49b809edbd08b266113d84dea8ea44 Mon Sep 17 00:00:00 2001 From: Guillermo Dev Date: Thu, 11 Oct 2018 01:40:58 +0200 Subject: [PATCH] testing file config, pass --- config/configuration.local.php | 45 ++++++++++++++++++++++++++++ src/Config/.Configuration.php.swp | Bin 0 -> 20480 bytes src/Config/Configuration.php | 46 ++++++++++++++++++++++------- tests/Config/ConfigurationTest.php | 15 ++++++++++ 4 files changed, 96 insertions(+), 10 deletions(-) create mode 100644 config/configuration.local.php create mode 100644 src/Config/.Configuration.php.swp diff --git a/config/configuration.local.php b/config/configuration.local.php new file mode 100644 index 0000000..0b38f28 --- /dev/null +++ b/config/configuration.local.php @@ -0,0 +1,45 @@ + 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, + ); + diff --git a/src/Config/.Configuration.php.swp b/src/Config/.Configuration.php.swp new file mode 100644 index 0000000000000000000000000000000000000000..63936af5b6cf88ec1be5399ff6e8b62f965a879a GIT binary patch literal 20480 zcmeI3Z;TY>9mmI_J#DcxZFyB+Ja=5!z3XvDsip?SNvH4Plp0>?QwJA1pbH?z#l za$JzMrU@o3_@XL(A+bp%nvjAoOkZe|CM~43@k9|KrY%NmU)V?!4XKhQru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em zHbWoW0%ypRyaKau5}t!+;SqQk9FY3}w!!$+*~ zUx0IP8eW5!;5a-6d*A`M9~QtTwAp!h0VY7T;Wac_$xY1__Z$@jnPwWN1+*oc&w7Msb5-1XD63F&gv+c|rV^8GJ*S69m%KHvXB)D{OBtvgPX zkIJyl1Z|ncb9JioWH;acGJjQ77r%_2U3PAyQ~&0-PnS!`H01kVbfPQXI)Wt0=8;Z{ zX5QtkJtea@E8qW;$@Vn6WWN7JZ&}D}puz7{|8LDK#^HO1eK$!$#mpl*?|&hm7S9Dn Gtp5PH463>S literal 0 HcmV?d00001 diff --git a/src/Config/Configuration.php b/src/Config/Configuration.php index 19bd720..acb0b3e 100644 --- a/src/Config/Configuration.php +++ b/src/Config/Configuration.php @@ -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()); } /** diff --git a/tests/Config/ConfigurationTest.php b/tests/Config/ConfigurationTest.php index 631965b..003a9e7 100644 --- a/tests/Config/ConfigurationTest.php +++ b/tests/Config/ConfigurationTest.php @@ -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)); + } }