ConfigTest.php
Go to the documentation of this file.00001 <?php
00002 print (basename(__FILE__).": Init...\n");
00003
00004
00005 @chdir("..");
00006
00007
00008 require(dirname(dirname(__FILE__)) . '/inc/config.php');
00009
00010
00011 require($cfg->readConfig('base_path') . 'inc/includes.php');
00012
00013
00014 require($cfg->readConfig('base_path') . 'inc/classes.php');
00015
00016
00017 FrameworkConfiguration::getInstance()->setConfigEntry('default_application', 'ship-simu');
00018
00019
00020 define('TEST_MODE', true);
00021
00022
00023 require_once('PHPUnit/Framework.php');
00024
00025 print (basename(__FILE__).": Init completed.\n\n");
00026
00050 class ConfigTest extends PHPUnit_Framework_TestCase {
00057 public function testConfigEntryNotFoundException () {
00058
00059 $testPassed = false;
00060 try {
00061
00062 $cfg = FrameworkConfiguration::getInstance();
00063
00064
00065 $dummy = $cfg->readConfig('does_not_exist');
00066 } catch (ConfigEntryNotFoundException $expected) {
00067
00068 $testPassed = true;
00069 } catch (FrameworkException $unexptected) {
00070
00071 $this->fail(sprintf("Unexpected exception %s detected.", $unexpected->__toString()));
00072 }
00073
00074 if (!$testPassed) {
00075
00076 $this->fail("Test of thrown exception ConfigEntryNotFoundException failed!");
00077 }
00078 }
00079
00086 public function testConfigEntryIsEmptyExceptionRead () {
00087
00088 $testPassed = false;
00089 try {
00090
00091 $cfg = FrameworkConfiguration::getInstance();
00092
00093
00094 $dummy = $cfg->readConfig("");
00095 } catch (ConfigEntryIsEmptyException $expected) {
00096
00097 $testPassed = true;
00098 } catch (FrameworkException $unexptected) {
00099
00100 $this->fail(sprintf("Unexpected exception %s detected.", $unexpected->__toString()));
00101 }
00102
00103 if (!$testPassed) {
00104
00105 $this->fail("Test of thrown exception ConfigEntryIsEmptyException failed!");
00106 }
00107 }
00108
00115 public function testConfigEntryIsEmptyExceptionWrite () {
00116
00117 $testPassed = false;
00118 try {
00119
00120 $cfg = FrameworkConfiguration::getInstance();
00121
00122
00123 $cfg->setConfigEntry("", 'will_never_be_set');
00124 } catch (ConfigEntryIsEmptyException $expected) {
00125
00126 $testPassed = true;
00127 } catch (FrameworkException $unexptected) {
00128
00129 $this->fail(sprintf("Unexpected exception %s detected.", $unexpected->__toString()));
00130 }
00131
00132 if (!$testPassed) {
00133
00134 $this->fail("Test of thrown exception ConfigEntryIsEmptyException failed!");
00135 }
00136 }
00137
00143 public function testWriteReadConfigEntry () {
00144
00145 $value = "This is a test value";
00146 try {
00147
00148 $cfg = FrameworkConfiguration::getInstance();
00149
00150
00151 $cfg->setConfigEntry('test_key', "{$value}");
00152
00153
00154 $readValue = $cfg->readConfig('test_key');
00155
00156
00157 $this->assertEquals($value, $readValue);
00158 } catch (FrameworkException $unexptected) {
00159
00160 $this->fail(sprintf("Unexpected exception %s detected.", $unexpected->__toString()));
00161 }
00162 }
00163 }
00164
00165 ?>