Skip to content
This repository
Browse code

Added Base Integration test class and unit testing of said class.

  • Loading branch information...
commit 0fe57ca47dfe4636de9592ce3f3e0afbc8f3bcfd 1 parent 25e5f82
Marke Hallowell authored March 09, 2010 gwoo committed March 12, 2010
38  libraries/lithium/test/Integration.php
... ...
@@ -0,0 +1,38 @@
  1
+<?php
  2
+/**
  3
+ * Lithium: the most rad php framework
  4
+ *
  5
+ * @copyright     Copyright 2010, Union of RAD (http://union-of-rad.org)
  6
+ * @license       http://opensource.org/licenses/bsd-license.php The BSD License
  7
+ */
  8
+
  9
+namespace lithium\test;
  10
+
  11
+class Integration extends \lithium\test\Unit {
  12
+
  13
+	/**
  14
+	 * Auto init for applying Integration filter
  15
+	 *
  16
+	 * @return void
  17
+	 */
  18
+	protected function _init() {
  19
+		parent::_init();
  20
+
  21
+		$this->applyFilter('run', function($self, $params, $chain) {
  22
+			$before = $self->results();
  23
+
  24
+			$chain->next($self, $params, $chain);
  25
+
  26
+			$after = $self->results();
  27
+
  28
+			while (count($after) > count($before)) {
  29
+				$result = array_pop($after);
  30
+				if ($result['result'] == 'fail') {
  31
+					return false;
  32
+				}
  33
+			}
  34
+		});
  35
+	}
  36
+}
  37
+
  38
+?>
15  libraries/lithium/test/Unit.php
@@ -536,7 +536,7 @@ protected function _result($type, $info, array $options = array()) {
536 536
 	 *
537 537
 	 * @param string $method The name of the test method to run.
538 538
 	 * @param array $options
539  
-	 * @return void
  539
+	 * @return void | false
540 540
 	 */
541 541
 	protected function _runTestMethod($method, $options) {
542 542
 		try {
@@ -547,7 +547,7 @@ protected function _runTestMethod($method, $options) {
547 547
 		}
548 548
 		$params = compact('options', 'method');
549 549
 
550  
-		$this->_filter(__CLASS__ . '::run', $params, function($self, $params, $chain) {
  550
+		$passed = $this->_filter(__CLASS__ . '::run', $params, function($self, $params, $chain) {
551 551
 			try {
552 552
 				$method = $params['method'];
553 553
 				$lineFlag = __LINE__ + 1;
@@ -557,6 +557,8 @@ protected function _runTestMethod($method, $options) {
557 557
 			}
558 558
 		});
559 559
 		$this->tearDown();
  560
+
  561
+		return $passed;
560 562
 	}
561 563
 
562 564
 	/**
@@ -797,6 +799,15 @@ protected function _cleanUp($path = null) {
797 799
 			($item->isDir()) ? rmdir($item->getPathname()) : unlink($item->getPathname());
798 800
 		}
799 801
 	}
  802
+
  803
+	/**
  804
+	 * Returns the current results
  805
+	 *
  806
+	 * @return array The Results, currently
  807
+	 */
  808
+	public function results() {
  809
+		return $this->_results;
  810
+	}
800 811
 }
801 812
 
802 813
 ?>
26  libraries/lithium/tests/cases/test/IntegrationTest.php
... ...
@@ -0,0 +1,26 @@
  1
+<?php
  2
+/**
  3
+ * Lithium: the most rad php framework
  4
+ *
  5
+ * @copyright     Copyright 2010, Union of RAD (http://union-of-rad.org)
  6
+ * @license       http://opensource.org/licenses/bsd-license.php The BSD License
  7
+ */
  8
+
  9
+namespace lithium\tests\cases\test;
  10
+
  11
+use \lithium\tests\mocks\test\MockIntegrationTest;
  12
+
  13
+class IntegrationTest extends \lithium\test\Unit {
  14
+
  15
+	public function testIntegrationHaltsOnFail() {
  16
+		$test = new MockIntegrationTest();
  17
+
  18
+		$expected = 2;
  19
+		$report = $test->run();
  20
+		$result = count($report);
  21
+
  22
+		$this->assertEqual($expected, $result);
  23
+	}
  24
+}
  25
+
  26
+?>
26  libraries/lithium/tests/mocks/test/MockIntegrationTest.php
... ...
@@ -0,0 +1,26 @@
  1
+<?php
  2
+/**
  3
+ * Lithium: the most rad php framework
  4
+ *
  5
+ * @copyright     Copyright 2010, Union of RAD (http://union-of-rad.org)
  6
+ * @license       http://opensource.org/licenses/bsd-license.php The BSD License
  7
+ */
  8
+
  9
+namespace lithium\tests\mocks\test;
  10
+
  11
+class MockIntegrationTest extends \lithium\test\Integration {
  12
+
  13
+	public function testPass() {
  14
+		$this->assertTrue(true);
  15
+	}
  16
+
  17
+	public function testFail() {
  18
+		$this->assertTrue(false);
  19
+	}
  20
+
  21
+	public function testAnotherPass() {
  22
+		$this->assertTrue(true);
  23
+	}
  24
+}
  25
+
  26
+?>

0 notes on commit 0fe57ca

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