ConfigTest.php

Go to the documentation of this file.
00001 <?php
00002 print (basename(__FILE__).": Init...\n");
00003 
00004 // Change directory
00005 @chdir("..");
00006 
00007 // Load config file
00008 require(dirname(dirname(__FILE__)) . '/inc/config.php');
00009 
00010 // Load all include files
00011 require($cfg->readConfig('base_path') . 'inc/includes.php');
00012 
00013 // Load all game classes
00014 require($cfg->readConfig('base_path') . 'inc/classes.php');
00015 
00016 // Set default application
00017 FrameworkConfiguration::getInstance()->setConfigEntry('default_application', 'ship-simu');
00018 
00019 // Set testing mode (no starter.php will be loaded!)
00020 define('TEST_MODE', true);
00021 
00022 // Load the PHPUnit framework
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                 // Now try the test
00059                 $testPassed = false;
00060                 try {
00061                         // Get a configuration instance
00062                         $cfg = FrameworkConfiguration::getInstance();
00063 
00064                         // Now find a configuration variable that does not exist
00065                         $dummy = $cfg->readConfig('does_not_exist');
00066                 } catch (ConfigEntryNotFoundException $expected) {
00067                         // This exception was expected, so it is fine
00068                         $testPassed = true;
00069                 } catch (FrameworkException $unexptected) {
00070                         // This exception was not expected!
00071                         $this->fail(sprintf("Unexpected exception %s detected.", $unexpected->__toString()));
00072                 }
00073 
00074                 if (!$testPassed) {
00075                         // This test went wrong
00076                         $this->fail("Test of thrown exception ConfigEntryNotFoundException failed!");
00077                 }
00078         }
00079 
00086         public function testConfigEntryIsEmptyExceptionRead () {
00087                 // Now try the test
00088                 $testPassed = false;
00089                 try {
00090                         // Get a configuration instance
00091                         $cfg = FrameworkConfiguration::getInstance();
00092 
00093                         // Try to read an empty configuration variable
00094                         $dummy = $cfg->readConfig("");
00095                 } catch (ConfigEntryIsEmptyException $expected) {
00096                         // This exception was expected, so it is fine
00097                         $testPassed = true;
00098                 } catch (FrameworkException $unexptected) {
00099                         // This exception was not expected!
00100                         $this->fail(sprintf("Unexpected exception %s detected.", $unexpected->__toString()));
00101                 }
00102 
00103                 if (!$testPassed) {
00104                         // This test went wrong
00105                         $this->fail("Test of thrown exception ConfigEntryIsEmptyException failed!");
00106                 }
00107         }
00108 
00115         public function testConfigEntryIsEmptyExceptionWrite () {
00116                 // Now try the test
00117                 $testPassed = false;
00118                 try {
00119                         // Get a configuration instance
00120                         $cfg = FrameworkConfiguration::getInstance();
00121 
00122                         // Try to read an empty configuration variable
00123                         $cfg->setConfigEntry("", 'will_never_be_set');
00124                 } catch (ConfigEntryIsEmptyException $expected) {
00125                         // This exception was expected, so it is fine
00126                         $testPassed = true;
00127                 } catch (FrameworkException $unexptected) {
00128                         // This exception was not expected!
00129                         $this->fail(sprintf("Unexpected exception %s detected.", $unexpected->__toString()));
00130                 }
00131 
00132                 if (!$testPassed) {
00133                         // This test went wrong
00134                         $this->fail("Test of thrown exception ConfigEntryIsEmptyException failed!");
00135                 }
00136         }
00137 
00143         public function testWriteReadConfigEntry () {
00144                 // Try it here
00145                 $value = "This is a test value";
00146                 try {
00147                         // Get a configuration instance
00148                         $cfg = FrameworkConfiguration::getInstance();
00149 
00150                         // Try to read an empty configuration variable
00151                         $cfg->setConfigEntry('test_key', "{$value}");
00152 
00153                         // Read the config entry we have just written
00154                         $readValue = $cfg->readConfig('test_key');
00155 
00156                         // Now test the values
00157                         $this->assertEquals($value, $readValue);
00158                 } catch (FrameworkException $unexptected) {
00159                         // This exception was not expected!
00160                         $this->fail(sprintf("Unexpected exception %s detected.", $unexpected->__toString()));
00161                 }
00162         }
00163 }
00164 
00165 ?>

Generated on Mon Dec 8 01:06:46 2008 for Ship-Simulator by  doxygen 1.5.6