[Fusionforge-commits] r9070 - in trunk: gforge/common/include tests/unit/config

Roland Mas lolando at libremir.placard.fr.eu.org
Mon Mar 15 14:04:12 CET 2010


Author: lolando
Date: 2010-03-15 14:04:12 +0100 (Mon, 15 Mar 2010)
New Revision: 9070

Modified:
   trunk/gforge/common/include/config.php
   trunk/tests/unit/config/ConfigTests.php
Log:
Added sample tests for a mock config object with different behaviour

Modified: trunk/gforge/common/include/config.php
===================================================================
--- trunk/gforge/common/include/config.php	2010-03-15 13:04:04 UTC (rev 9069)
+++ trunk/gforge/common/include/config.php	2010-03-15 13:04:12 UTC (rev 9070)
@@ -23,7 +23,7 @@
  */
 
 class FusionForgeConfig {
-	static private $instance = NULL ;
+	static protected $instance = NULL ;
 	private $settings ;
     
 	public function get_instance () {

Modified: trunk/tests/unit/config/ConfigTests.php
===================================================================
--- trunk/tests/unit/config/ConfigTests.php	2010-03-15 13:04:04 UTC (rev 9069)
+++ trunk/tests/unit/config/ConfigTests.php	2010-03-15 13:04:12 UTC (rev 9070)
@@ -18,7 +18,6 @@
 	 */
 	public function testBasicConfig()
 	{
-		$c = FusionForgeConfig::get_instance () ;
 		fusionforge_define_config_item ('forge_name', 'core', 'default') ;
 
 		$this->assertEquals('default', fusionforge_get_config ('forge_name'));
@@ -30,4 +29,43 @@
 		$this->assertEquals('FusionForge', fusionforge_get_config ('forge_name', 'core'));
 	}
 
+	/**
+	 * test mock config system
+	 */
+	public function testMockConfig()
+	{
+		MockConfig::insinuate () ;
+		fusionforge_define_config_item ('forge_name', 'core', 'default') ;
+
+		$this->assertEquals('core/forge_name', fusionforge_get_config ('forge_name'));
+		$this->assertEquals('core/forge_name', fusionforge_get_config ('forge_name', 'core'));
+
+		MockConfig::cleanup () ;
+		fusionforge_define_config_item ('forge_name', 'core', 'default') ;
+
+		$this->assertEquals('default', fusionforge_get_config ('forge_name'));
+	}
+
 }
+
+class MockConfig extends FusionForgeConfig {
+	public function insinuate () {
+		parent::$instance = NULL ;
+		self::get_instance () ;
+	}
+
+	public function cleanup () {
+		parent::$instance = NULL ;
+	}
+		
+	public function get_instance () {
+		if (parent::$instance == NULL) {
+			parent::$instance = new MockConfig () ;
+		}
+		return parent::$instance ;
+	}
+	
+	public function get_value ($section, $var) {
+		return "$section/$var" ;
+	}
+}
\ No newline at end of file




More information about the Fusionforge-commits mailing list