6 require(dirname(dirname(__FILE__)) . "/inc/config.php");
8 // Load all include files
9 require(PATH . "inc/includes.php");
11 // Load all game classes
12 require(PATH . "inc/classes.php");
14 // Set default application
15 FrameworkConfiguration::getInstance()->setConfigEntry("default_application", "ship-simu");
17 // Set testing mode (no starter.php will be loaded!)
18 define('TEST_MODE', true);
20 // Load the PHPUnit framework
21 require_once("PHPUnit/Framework.php");
24 * A test case for the configuration sub system
26 * @author Roland Haeder <webmaster@mxchange.org>
28 * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software
29 * @license GNU GPL 3.0 or any newer version
30 * @link http://www.ship-simu.org
31 * @see http://www.phpunit.de
33 * This program is free software: you can redistribute it and/or modify
34 * it under the terms of the GNU General Public License as published by
35 * the Free Software Foundation, either version 3 of the License, or
36 * (at your option) any later version.
38 * This program is distributed in the hope that it will be useful,
39 * but WITHOUT ANY WARRANTY; without even the implied warranty of
40 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41 * GNU General Public License for more details.
43 * You should have received a copy of the GNU General Public License
44 * along with this program. If not, see <http://www.gnu.org/licenses/>.
46 class ConfigTest extends PHPUnit_Framework_TestCase {
48 * Tests the exception ConfigEntryNotFoundException if it is being thrown.
49 * Else the test shall fail
53 public function testConfigEntryNotFoundException () {
57 // Get a configuration instance
58 $cfg = FrameworkConfiguration::getInstance();
60 // Now find a configuration variable that does not exist
61 $dummy = $cfg->readConfig("does_not_exist");
62 } catch (ConfigEntryNotFoundException $expected) {
63 // This exception was expected, so it is fine
65 } catch (FrameworkException $unexptected) {
66 // This exception was not expected!
67 $this->fail(sprintf("Unexpected exception %s detected.", $unexpected->__toString()));
71 // This test went wrong
72 $this->fail("Test of thrown exception ConfigEntryNotFoundException failed!");
77 * Tests if the exception ConfigEntryIsEmptyException is being thrown by
78 * "emulating" an empty configuration variable.
82 public function testConfigEntryIsEmptyExceptionRead () {
86 // Get a configuration instance
87 $cfg = FrameworkConfiguration::getInstance();
89 // Try to read an empty configuration variable
90 $dummy = $cfg->readConfig("");
91 } catch (ConfigEntryIsEmptyException $expected) {
92 // This exception was expected, so it is fine
94 } catch (FrameworkException $unexptected) {
95 // This exception was not expected!
96 $this->fail(sprintf("Unexpected exception %s detected.", $unexpected->__toString()));
100 // This test went wrong
101 $this->fail("Test of thrown exception ConfigEntryIsEmptyException failed!");
106 * Tests if the exception ConfigEntryIsEmptyException is being thrown by
107 * "emulating" an empty configuration variable.
111 public function testConfigEntryIsEmptyExceptionWrite () {
115 // Get a configuration instance
116 $cfg = FrameworkConfiguration::getInstance();
118 // Try to read an empty configuration variable
119 $cfg->setConfigEntry("", "will_never_be_set");
120 } catch (ConfigEntryIsEmptyException $expected) {
121 // This exception was expected, so it is fine
123 } catch (FrameworkException $unexptected) {
124 // This exception was not expected!
125 $this->fail(sprintf("Unexpected exception %s detected.", $unexpected->__toString()));
129 // This test went wrong
130 $this->fail("Test of thrown exception ConfigEntryIsEmptyException failed!");
135 * Tests if a set value can be returned from the configuration sub-system
139 public function testWriteReadConfigEntry () {
141 $value = "This is a test value";
143 // Get a configuration instance
144 $cfg = FrameworkConfiguration::getInstance();
146 // Try to read an empty configuration variable
147 $cfg->setConfigEntry("test_key", "{$value}");
149 // Read the config entry we have just written
150 $readValue = $cfg->readConfig("test_key");
152 // Now test the values
153 $this->assertEquals($value, $readValue);
154 } catch (FrameworkException $unexptected) {
155 // This exception was not expected!
156 $this->fail(sprintf("Unexpected exception %s detected.", $unexpected->__toString()));