getConfigEntry('base_path') . 'inc/includes.php'); // Load all game classes require($cfg->getConfigEntry('base_path') . 'inc/classes.php'); // Set default application FrameworkConfiguration::getInstance()->setConfigEntry('default_application', 'shipsimu'); // Set testing mode (no starter.php will be loaded!) define('TEST_MODE', true); // Load the PHPUnit framework require('PHPUnit/Framework.php'); print (basename(__FILE__).": Init completed.\n\n"); /** * A test case for the configuration sub system * * @author Roland Haeder * @version 0.0.0 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Core Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.shipsimu.org * @see http://www.phpunit.de * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ class ConfigTest extends PHPUnit_Framework_TestCase { /** * Tests the exception ConfigEntryNotFoundException if it is being thrown. * Else the test shall fail * * @return void */ public function testConfigEntryNotFoundException () { // Now try the test $testPassed = false; try { // Now find a configuration variable that does not exist $dummy = FrameworkConfiguration::getInstance()->getConfigEntry('does_not_exist'); } catch (ConfigEntryNotFoundException $expected) { // This exception was expected, so it is fine $testPassed = true; } catch (FrameworkException $unexptected) { // This exception was not expected! $this->fail(sprintf("Unexpected exception %s detected.", $unexpected->__toString())); } if (!$testPassed) { // This test went wrong $this->fail("Test of thrown exception ConfigEntryNotFoundException failed!"); } } /** * Tests if the exception ConfigEntryIsEmptyException is being thrown by * "emulating" an empty configuration variable. * * @return void */ public function testConfigEntryIsEmptyExceptionRead () { // Now try the test $testPassed = false; try { // Try to read an empty configuration variable $dummy = FrameworkConfiguration::getInstance()->getConfigEntry(''); } catch (ConfigEntryIsEmptyException $expected) { // This exception was expected, so it is fine $testPassed = true; } catch (FrameworkException $unexptected) { // This exception was not expected! $this->fail(sprintf("Unexpected exception %s detected.", $unexpected->__toString())); } if (!$testPassed) { // This test went wrong $this->fail("Test of thrown exception ConfigEntryIsEmptyException failed!"); } } /** * Tests if the exception ConfigEntryIsEmptyException is being thrown by * "emulating" an empty configuration variable. * * @return void */ public function testConfigEntryIsEmptyExceptionWrite () { // Now try the test $testPassed = false; try { // Try to read an empty configuration variable FrameworkConfiguration::getInstance()->setConfigEntry('', 'will_never_be_set'); } catch (ConfigEntryIsEmptyException $expected) { // This exception was expected, so it is fine $testPassed = true; } catch (FrameworkException $unexptected) { // This exception was not expected! $this->fail(sprintf("Unexpected exception %s detected.", $unexpected->__toString())); } if (!$testPassed) { // This test went wrong $this->fail("Test of thrown exception ConfigEntryIsEmptyException failed!"); } } /** * Tests if a set value can be returned from the configuration sub-system * * @return void */ public function testWritegetConfigEntryEntry () { // Try it here $value = "This is a test value"; try { // Try to read an empty configuration variable FrameworkConfiguration::getInstance()->setConfigEntry('test_key', "{$value}"); // Read the config entry we have just written $readValue = FrameworkConfiguration::getInstance()->getConfigEntry('test_key'); // Now test the values $this->assertEquals($value, $readValue); } catch (FrameworkException $unexptected) { // This exception was not expected! $this->fail(sprintf("Unexpected exception %s detected.", $unexpected->__toString())); } } } ?>