2 print (basename(__FILE__).": Init...\n");
8 require(dirname(dirname(__FILE__)) . '/inc/config.php');
10 // Load all include files
11 require($cfg->readConfig('base_path') . 'inc/includes.php');
13 // Load all game classes
14 require($cfg->readConfig('base_path') . 'inc/classes.php');
16 // Set default application
17 FrameworkConfiguration::getInstance()->setConfigEntry('default_application', 'ship-simu');
19 // Set testing mode (no starter.php will be loaded!)
20 define('TEST_MODE', true);
22 // Load the PHPUnit framework
23 require_once('PHPUnit/Framework.php');
25 print (basename(__FILE__).": Init completed.\n\n");
28 * A test case for the configuration sub system
30 * @author Roland Haeder <webmaster@ship-simu.org>
32 * @copyright Copyright (c) 2007, 2008 Roland Haeder, this is free software
33 * @license GNU GPL 3.0 or any newer version
34 * @link http://www.ship-simu.org
35 * @see http://www.phpunit.de
37 * This program is free software: you can redistribute it and/or modify
38 * it under the terms of the GNU General Public License as published by
39 * the Free Software Foundation, either version 3 of the License, or
40 * (at your option) any later version.
42 * This program is distributed in the hope that it will be useful,
43 * but WITHOUT ANY WARRANTY; without even the implied warranty of
44 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45 * GNU General Public License for more details.
47 * You should have received a copy of the GNU General Public License
48 * along with this program. If not, see <http://www.gnu.org/licenses/>.
50 class ConfigTest extends PHPUnit_Framework_TestCase {
52 * Tests the exception ConfigEntryNotFoundException if it is being thrown.
53 * Else the test shall fail
57 public function testConfigEntryNotFoundException () {
61 // Get a configuration instance
62 $cfg = FrameworkConfiguration::getInstance();
64 // Now find a configuration variable that does not exist
65 $dummy = $cfg->readConfig('does_not_exist');
66 } catch (ConfigEntryNotFoundException $expected) {
67 // This exception was expected, so it is fine
69 } catch (FrameworkException $unexptected) {
70 // This exception was not expected!
71 $this->fail(sprintf("Unexpected exception %s detected.", $unexpected->__toString()));
75 // This test went wrong
76 $this->fail("Test of thrown exception ConfigEntryNotFoundException failed!");
81 * Tests if the exception ConfigEntryIsEmptyException is being thrown by
82 * "emulating" an empty configuration variable.
86 public function testConfigEntryIsEmptyExceptionRead () {
90 // Get a configuration instance
91 $cfg = FrameworkConfiguration::getInstance();
93 // Try to read an empty configuration variable
94 $dummy = $cfg->readConfig("");
95 } catch (ConfigEntryIsEmptyException $expected) {
96 // This exception was expected, so it is fine
98 } catch (FrameworkException $unexptected) {
99 // This exception was not expected!
100 $this->fail(sprintf("Unexpected exception %s detected.", $unexpected->__toString()));
104 // This test went wrong
105 $this->fail("Test of thrown exception ConfigEntryIsEmptyException failed!");
110 * Tests if the exception ConfigEntryIsEmptyException is being thrown by
111 * "emulating" an empty configuration variable.
115 public function testConfigEntryIsEmptyExceptionWrite () {
119 // Get a configuration instance
120 $cfg = FrameworkConfiguration::getInstance();
122 // Try to read an empty configuration variable
123 $cfg->setConfigEntry("", 'will_never_be_set');
124 } catch (ConfigEntryIsEmptyException $expected) {
125 // This exception was expected, so it is fine
127 } catch (FrameworkException $unexptected) {
128 // This exception was not expected!
129 $this->fail(sprintf("Unexpected exception %s detected.", $unexpected->__toString()));
133 // This test went wrong
134 $this->fail("Test of thrown exception ConfigEntryIsEmptyException failed!");
139 * Tests if a set value can be returned from the configuration sub-system
143 public function testWriteReadConfigEntry () {
145 $value = "This is a test value";
147 // Get a configuration instance
148 $cfg = FrameworkConfiguration::getInstance();
150 // Try to read an empty configuration variable
151 $cfg->setConfigEntry('test_key', "{$value}");
153 // Read the config entry we have just written
154 $readValue = $cfg->readConfig('test_key');
156 // Now test the values
157 $this->assertEquals($value, $readValue);
158 } catch (FrameworkException $unexptected) {
159 // This exception was not expected!
160 $this->fail(sprintf("Unexpected exception %s detected.", $unexpected->__toString()));