Skip to content
This repository
Browse code

MINOR Tidy up of code formatting in TestRunner

MINOR Fixing up old ObjectStaticTest and merging into ConfigTest
  • Loading branch information...
commit 16e950cb6aa9d80912724124ef0ad826f641c6dd 1 parent 4c6be29
Sean Harvey authored April 18, 2012
2  admin/code/CMSBatchActionHandler.php
@@ -203,7 +203,7 @@ function batchActionList() {
203 203
 	 * @return array See {@link register()} for the returned format.
204 204
 	 */
205 205
 	function batchActions() {
206  
-		$actions = Config::inst()->get($this->class, 'batch_actions', Config::FIRST_SET)
  206
+		$actions = Config::inst()->get($this->class, 'batch_actions', Config::FIRST_SET);
207 207
 		if($actions) foreach($actions as $action) {
208 208
 			if($action['recordClass'] != $this->recordClass) unset($action);
209 209
 		}
25  dev/TestRunner.php
@@ -254,19 +254,20 @@ function module($request, $coverage = false) {
254 254
 	 */
255 255
 	function runTests($classList, $coverage = false) {
256 256
 		$startTime = microtime(true);
257  
-		
258  
-		// XDEBUG seem to cause problems with test execution :-(
  257
+
  258
+		// disable xdebug, as it messes up test execution
259 259
 		if(function_exists('xdebug_disable')) xdebug_disable();
260  
-		
261  
-		ini_set('max_execution_time', 0);		
262  
-		
  260
+
  261
+		ini_set('max_execution_time', 0);
  262
+
263 263
 		$this->setUp();
264  
-		
  264
+
265 265
 		// Optionally skip certain tests
266 266
 		$skipTests = array();
267 267
 		if($this->request->getVar('SkipTests')) {
268 268
 			$skipTests = explode(',', $this->request->getVar('SkipTests'));
269 269
 		}
  270
+
270 271
 		$classList = array_diff($classList, $skipTests);
271 272
 		
272 273
 		// run tests before outputting anything to the client
@@ -281,16 +282,14 @@ class_exists($className);
281 282
 		// Remove the error handler so that PHPUnit can add its own
282 283
 		restore_error_handler();
283 284
 
284  
-
285 285
 		self::$default_reporter->writeHeader("SilverStripe Test Runner");
286  
-		if (count($classList) > 1) { 
  286
+		if (count($classList) > 1) {
287 287
 			self::$default_reporter->writeInfo("All Tests", "Running test cases: ",implode(", ", $classList));
288  
-		} else
289  
-		if (count($classList) == 1) { 
290  
-			self::$default_reporter->writeInfo($classList[0], "");
  288
+		} elseif (count($classList) == 1) {
  289
+			self::$default_reporter->writeInfo($classList[0], '');
291 290
 		} else {
292  
-			// border case: no tests are available. 
293  
-			self::$default_reporter->writeInfo("", "");
  291
+			// border case: no tests are available.
  292
+			self::$default_reporter->writeInfo('', '');
294 293
 		}
295 294
 
296 295
 		// perform unit tests (use PhpUnitWrapper or derived versions)
86  tests/core/ConfigTest.php
@@ -17,8 +17,94 @@ class ConfigTest_DefinesFooDoesntExtendObject {
17 17
 	protected static $foo = 4;
18 18
 }
19 19
 
  20
+class ConfigStaticTest_First extends Config {
  21
+	public static $first  = array('test_1');
  22
+	public static $second = array('test_1');
  23
+	public static $third  = 'test_1';
  24
+}
  25
+
  26
+class ConfigStaticTest_Second extends ConfigStaticTest_First {
  27
+	public static $first = array('test_2');
  28
+}
  29
+
  30
+class ConfigStaticTest_Third extends ConfigStaticTest_Second {
  31
+	public static $first  = array('test_3');
  32
+	public static $second = array('test_3');
  33
+	public static $fourth = array('test_3');
  34
+}
  35
+
  36
+class ConfigStaticTest_Fourth extends ConfigStaticTest_Third {
  37
+	public static $fourth = array('test_4');
  38
+}
  39
+
  40
+class ConfigStaticTest_Combined1 extends Config {
  41
+	public static $first  = array('test_1');
  42
+	public static $second = array('test_1');
  43
+}
  44
+
  45
+class ConfigStaticTest_Combined2 extends ConfigStaticTest_Combined1 {
  46
+	public static $first  = array('test_2');
  47
+	public static $second = null;
  48
+}
  49
+
  50
+class ConfigStaticTest_Combined3 extends ConfigStaticTest_Combined2 {
  51
+	public static $first  = array('test_3');
  52
+	public static $second = array('test_3');
  53
+}
  54
+
20 55
 class ConfigTest extends SapphireTest {
21 56
 
  57
+	function testUpdateStatic() {
  58
+		$this->assertEquals(Config::inst()->get('ConfigStaticTest_First', 'first', Config::FIRST_SET), array('test_1'));
  59
+		$this->assertEquals(Config::inst()->get('ConfigStaticTest_Second', 'first', Config::FIRST_SET), array('test_2'));
  60
+		$this->assertEquals(Config::inst()->get('ConfigStaticTest_Third', 'first', Config::FIRST_SET), array('test_3'));
  61
+
  62
+		Config::inst()->update('ConfigStaticTest_First', 'first', array('test_1_2'));
  63
+		Config::inst()->update('ConfigStaticTest_Third', 'first', array('test_3_2'));
  64
+		Config::inst()->update('ConfigStaticTest_Fourth', 'first', array('test_4'));
  65
+
  66
+		$this->assertEquals(Config::inst()->get('ConfigStaticTest_First', 'first', Config::FIRST_SET), array('test_1_2', 'test_1'));
  67
+
  68
+		Config::inst()->update('ConfigStaticTest_Fourth', 'second', array('test_4'));
  69
+		Config::inst()->update('ConfigStaticTest_Third', 'second', array('test_3_2'));
  70
+
  71
+		$this->assertEquals(Config::inst()->get('ConfigStaticTest_Fourth', 'second', Config::FIRST_SET), array('test_4'));
  72
+		$this->assertEquals(Config::inst()->get('ConfigStaticTest_Third', 'second', Config::FIRST_SET), array('test_3_2', 'test_3'));
  73
+
  74
+		Config::inst()->remove('ConfigStaticTest_Third', 'second');
  75
+		Config::inst()->update('ConfigStaticTest_Third', 'second', array('test_3_2'));
  76
+		$this->assertEquals(Config::inst()->get('ConfigStaticTest_Third', 'second', Config::FIRST_SET), array('test_3_2'));
  77
+	}
  78
+
  79
+	function testUninheritedStatic() {
  80
+		$this->assertEquals(Config::inst()->get('ConfigStaticTest_First',  'third', Config::UNINHERITED), 'test_1');
  81
+		$this->assertEquals(Config::inst()->get('ConfigStaticTest_Fourth', 'third', Config::UNINHERITED), null);
  82
+
  83
+		Config::inst()->update('ConfigStaticTest_First', 'first', array('test_1b'));
  84
+		Config::inst()->update('ConfigStaticTest_Second', 'first', array('test_2b'));
  85
+
  86
+		// Check that it can be applied to parent and subclasses, and queried directly
  87
+		$this->assertContains('test_1b', Config::inst()->get('ConfigStaticTest_First', 'first', Config::UNINHERITED));
  88
+		$this->assertContains('test_2b', Config::inst()->get('ConfigStaticTest_Second', 'first', Config::UNINHERITED));
  89
+
  90
+		// But it won't affect subclasses - this is *uninherited* static
  91
+		$this->assertNotContains('test_2b', Config::inst()->get('ConfigStaticTest_Third', 'first', Config::UNINHERITED));
  92
+		$this->assertNotContains('test_2b', Config::inst()->get('ConfigStaticTest_Fourth', 'first', Config::UNINHERITED));
  93
+
  94
+		// Subclasses that don't have the static explicitly defined should allow definition, also
  95
+		// This also checks that set can be called after the first uninherited get() 
  96
+		// call (which can be buggy due to caching) 
  97
+		Config::inst()->update('ConfigStaticTest_Fourth', 'first', array('test_4b'));
  98
+		$this->assertContains('test_4b', Config::inst()->get('ConfigStaticTest_Fourth', 'first', Config::UNINHERITED));
  99
+	}
  100
+
  101
+	function testCombinedStatic() {
  102
+		$this->assertEquals(Config::inst()->get('ConfigStaticTest_Combined3', 'first'), array('test_3', 'test_2', 'test_1'));
  103
+
  104
+		// test that null values are ignored, but values on either side are still merged
  105
+		$this->assertEquals(Config::inst()->get('ConfigStaticTest_Combined3', 'second'), array('test_3', 'test_1'));
  106
+	}
  107
+
22 108
 	function testMerges() {
23 109
 		$result = array('A' => 1, 'B' => 2, 'C' => 3);
24 110
 		Config::merge_array_low_into_high($result, array('C' => 4, 'D' => 5));
136  tests/core/ObjectStaticTest.php
... ...
@@ -1,136 +0,0 @@
1  
-<?php
2  
-/**
3  
- * Tests various static getter and setter methods on {@link Object}
4  
- *
5  
- * @package framework
6  
- * @subpackage tests
7  
- */
8  
-class ObjectStaticTest extends SapphireTest {
9  
-	
10  
-	/**
11  
-	 * Tests {@link Object::get_static()}
12  
-	 */
13  
-	public function testGetStatic() {
14  
-		$this->assertEquals(Object::get_static('ObjectStaticTest_First',  'first'), array('test_1'));
15  
-		$this->assertEquals(Object::get_static('ObjectStaticTest_Second', 'first'), array('test_2'));
16  
-		$this->assertEquals(Object::get_static('ObjectStaticTest_Third',  'first'), array('test_3'));
17  
-		
18  
-		Object::addStaticVars('ObjectStaticTest_First',  array('first' => array('test_1_2')));
19  
-		Object::addStaticVars('ObjectStaticTest_Third',  array('first' => array('test_3_2')));
20  
-		Object::addStaticVars('ObjectStaticTest_Fourth', array('first' => array('test_4')));
21  
-		
22  
-		$this->assertEquals(Object::get_static('ObjectStaticTest_First',  'first', true), array('test_1_2', 'test_1'));
23  
-		// @todo - This fails. Decide if we can ignore this particular behaviour (it seems weird and counter-intuitive anyway)
24  
-		// $this->assertEquals(Object::get_static('ObjectStaticTest_Second', 'first', true), array('test_1_2', 'test_2'));
25  
-		// $this->assertEquals(Object::get_static('ObjectStaticTest_Third',  'first', true), array('test_1_2', 'test_3_2', 'test_3'));
26  
-	}
27  
-	
28  
-	/**
29  
-	 * Test {@link Object::addStaticVar()} correctly replaces static vars
30  
-	 */
31  
-	public function testAddStaticReplace() {
32  
-		Object::addStaticVars('ObjectStaticTest_Fourth', array('second' => array('test_4')), true);
33  
-		Object::addStaticVars('ObjectStaticTest_Third',  array('second' => array('test_3_2')));
34  
-		
35  
-		$this->assertEquals(Object::get_static('ObjectStaticTest_Fourth', 'second', true), array('test_4'));
36  
-		$this->assertEquals(Object::get_static('ObjectStaticTest_Third',  'second', true), array('test_3_2', 'test_3'));
37  
-		
38  
-		Object::addStaticVars('ObjectStaticTest_Third',  array('second' => array('test_3_2')), true);
39  
-		$this->assertEquals(Object::get_static('ObjectStaticTest_Third', 'second', true), array('test_3_2'));
40  
-		
41  
-		Object::add_static_var('ObjectStaticTest_Third', 'fourth', array('test_3_2'));
42  
-		// @todo - This fails. Decide if we can ignore this particular behaviour (it seems weird and counter-intuitive anyway)
43  
-		// $this->assertEquals(Object::get_static('ObjectStaticTest_Fourth', 'fourth', true), array('test_3_2', 'test_4'));
44  
-
45  
-		Object::add_static_var('ObjectStaticTest_Third', 'fourth', array('test_3_2'), true);
46  
-		// @todo - This fails. Decide if we can ignore this particular behaviour (it seems weird and counter-intuitive anyway)
47  
-		// $this->assertEquals(Object::get_static('ObjectStaticTest_Fourth', 'fourth', true), array('test_4', 'test_3_2'));
48  
-	}
49  
-	
50  
-	/**
51  
-	 * Tests {@link Object::uninherited_static()}
52  
-	 */
53  
-	public function testUninherited() {
54  
-		$this->assertEquals(Object::uninherited_static('ObjectStaticTest_First',  'third', true), 'test_1');
55  
-		$this->assertEquals(Object::uninherited_static('ObjectStaticTest_Fourth', 'third', true), null);
56  
-	}
57  
-	
58  
-	public function testCombinedStatic() {
59  
-		// test basic operation
60  
-		$this->assertEquals (
61  
-			array('test_3', 'test_2', 'test_1'), Object::combined_static('ObjectStaticTest_Combined3', 'first')
62  
-		);
63  
-		
64  
-		// test that null values are ignored, but values on either side are still merged
65  
-		$this->assertEquals (
66  
-			array('test_3', 'test_1'), Object::combined_static('ObjectStaticTest_Combined3', 'second')
67  
-		);
68  
-		
69  
-		// test the $ceiling param
70  
-		// @todo - This fails, as it's been removed. Do we need it?
71  
-		// $this->assertEquals (
72  
-		//	  array('test_3', 'test_2'), Object::combined_static('ObjectStaticTest_Combined3', 'first', 'ObjectStaticTest_Combined2')
73  
-		// );
74  
-	}
75  
-	
76  
-	/**
77  
-	 * Checks that Object::add_static_var() also works for uninherited stats
78  
-	 */
79  
-	public function testAddStaticVarWorksForUninheritedStatics() {
80  
-		Object::add_static_var('ObjectStaticTest_First', 'first', array('test_1b'));
81  
-		Object::add_static_var('ObjectStaticTest_Second', 'first', array('test_2b'));
82  
-		
83  
-		// Check that it can be applied to parent and subclasses, and queried directly
84  
-		$this->assertContains('test_1b', Object::uninherited_static('ObjectStaticTest_First', 'first'));
85  
-		$this->assertContains('test_2b', Object::uninherited_static('ObjectStaticTest_Second', 'first'));
86  
-
87  
-		// But it won't affect subclasses - this is *uninherited* static
88  
-		$this->assertNotContains('test_2b', Object::uninherited_static('ObjectStaticTest_Third', 'first'));
89  
-		$this->assertNotContains('test_2b', Object::uninherited_static('ObjectStaticTest_Fourth', 'first'));
90  
-
91  
-		// Subclasses that don't have the static explicitly defined should allow definition, also
92  
-		// This also checks that add_static_var can be called after the first uninherited_static() 
93  
-		// call (which can be buggy due to caching) 
94  
-		Object::add_static_var('ObjectStaticTest_Fourth', 'first', array('test_4b'));
95  
-		$this->assertContains('test_4b', Object::uninherited_static('ObjectStaticTest_Fourth', 'first'));
96  
-	}
97  
-	
98  
-}
99  
-
100  
-/**#@+
101  
- * @ignore
102  
- */
103  
-class ObjectStaticTest_First extends Object {
104  
-	public static $first  = array('test_1');
105  
-	public static $second = array('test_1');
106  
-	public static $third  = 'test_1';
107  
-}
108  
-
109  
-class ObjectStaticTest_Second extends ObjectStaticTest_First {
110  
-	public static $first = array('test_2');
111  
-}
112  
-
113  
-class ObjectStaticTest_Third extends ObjectStaticTest_Second {
114  
-	public static $first  = array('test_3');
115  
-	public static $second = array('test_3');
116  
-	public static $fourth = array('test_3');
117  
-}
118  
-
119  
-class ObjectStaticTest_Fourth extends ObjectStaticTest_Third {
120  
-	public static $fourth = array('test_4');
121  
-}
122  
-
123  
-class ObjectStaticTest_Combined1 extends Object {
124  
-	public static $first  = array('test_1');
125  
-	public static $second = array('test_1');
126  
-}
127  
-
128  
-class ObjectStaticTest_Combined2 extends ObjectStaticTest_Combined1 {
129  
-	public static $first  = array('test_2');
130  
-	public static $second = null;
131  
-}
132  
-
133  
-class ObjectStaticTest_Combined3 extends ObjectStaticTest_Combined2 {
134  
-	public static $first  = array('test_3');
135  
-	public static $second = array('test_3');
136  
-}
2  tests/model/DataObjectTest.php
@@ -1021,9 +1021,11 @@ function testRelField() {
1021 1021
 
1022 1022
 	function testRelObject() {
1023 1023
 		$captain = $this->objFromFixture('DataObjectTest_Player', 'captain1');
  1024
+
1024 1025
 		// Test traversal of a single has_one
1025 1026
 		$this->assertInstanceOf("Varchar", $captain->relObject('FavouriteTeam.Title'));
1026 1027
 		$this->assertEquals("Team 1", $captain->relObject('FavouriteTeam.Title')->getValue());
  1028
+
1027 1029
 		// Test direct field access
1028 1030
 		$this->assertInstanceOf("Boolean", $captain->relObject('IsRetired'));
1029 1031
 		$this->assertEquals(1, $captain->relObject('IsRetired')->getValue());

0 notes on commit 16e950c

Please sign in to comment.
Something went wrong with that request. Please try again.