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
27 class ConfigTest extends PHPUnit_Framework_TestCase {
29 * Tests the exception ConfigEntryNotFoundException if it is being thrown.
30 * Else the test shall fail
34 public function testConfigEntryNotFoundException () {
38 // Get a configuration instance
39 $cfg = FrameworkConfiguration::getInstance();
41 // Now find a configuration variable that does not exist
42 $dummy = $cfg->readConfig("does_not_exist");
43 } catch (ConfigEntryNotFoundException $expected) {
44 // This exception was expected, so it is fine
46 } catch (FrameworkException $unexptected) {
47 // This exception was not expected!
48 $this->fail(sprintf("Unexpected exception %s detected.", $unexpected->__toString()));
52 // This test went wrong
53 $this->fail("Test of thrown exception ConfigEntryNotFoundException failed!");
58 * Tests if the exception ConfigEntryIsEmptyException is being thrown by
59 * "emulating" an empty configuration variable.
63 public function testConfigEntryIsEmptyExceptionRead () {
67 // Get a configuration instance
68 $cfg = FrameworkConfiguration::getInstance();
70 // Try to read an empty configuration variable
71 $dummy = $cfg->readConfig("");
72 } catch (ConfigEntryIsEmptyException $expected) {
73 // This exception was expected, so it is fine
75 } catch (FrameworkException $unexptected) {
76 // This exception was not expected!
77 $this->fail(sprintf("Unexpected exception %s detected.", $unexpected->__toString()));
81 // This test went wrong
82 $this->fail("Test of thrown exception ConfigEntryIsEmptyException failed!");
87 * Tests if the exception ConfigEntryIsEmptyException is being thrown by
88 * "emulating" an empty configuration variable.
92 public function testConfigEntryIsEmptyExceptionWrite () {
96 // Get a configuration instance
97 $cfg = FrameworkConfiguration::getInstance();
99 // Try to read an empty configuration variable
100 $cfg->setConfigEntry("", "will_never_be_set");
101 } catch (ConfigEntryIsEmptyException $expected) {
102 // This exception was expected, so it is fine
104 } catch (FrameworkException $unexptected) {
105 // This exception was not expected!
106 $this->fail(sprintf("Unexpected exception %s detected.", $unexpected->__toString()));
110 // This test went wrong
111 $this->fail("Test of thrown exception ConfigEntryIsEmptyException failed!");
116 * Tests if a set value can be returned from the configuration sub-system
120 public function testWriteReadConfigEntry () {
122 $value = "This is a test value";
124 // Get a configuration instance
125 $cfg = FrameworkConfiguration::getInstance();
127 // Try to read an empty configuration variable
128 $cfg->setConfigEntry("test_key", "{$value}");
130 // Read the config entry we have just written
131 $readValue = $cfg->readConfig("test_key");
133 // Now test the values
134 $this->assertEquals($value, $readValue);
135 } catch (FrameworkException $unexptected) {
136 // This exception was not expected!
137 $this->fail(sprintf("Unexpected exception %s detected.", $unexpected->__toString()));