Permalink
Browse files

exceptions thrown in setUp and tearDown cause silent end of testcases…

… being run

testcase for #514.
Also had to swap the lines in tesstRun to make it pass

Test case will cause silent ending on running
- /tests/cases/test
- /tests/cases/test/Dispatcher
- tests/cases/test/UnitTest
  • Loading branch information...
1 parent 3d4c712 commit 2f7f4dbfc7ed7f7eef0e76ccb1e18bfc408fdb52 @hans-d committed Jun 12, 2012
@@ -13,6 +13,8 @@
use lithium\tests\mocks\test\MockUnitTest;
use lithium\tests\mocks\test\cases\MockSkipThrowsException;
use lithium\tests\mocks\test\cases\MockTestErrorHandling;
+use lithium\tests\mocks\test\cases\MockSetUpThrowsException;
+use lithium\tests\mocks\test\cases\MockTearDownThrowsException;
class UnitTest extends \lithium\test\Unit {
@@ -175,13 +177,13 @@ public function testRun() {
$file = realpath(LITHIUM_LIBRARY_PATH) . '/lithium/tests/mocks/test/MockUnitTest.php';
$expected = array(
'result' => 'pass',
+ 'class' => 'lithium\\tests\\mocks\\test\\MockUnitTest',
+ 'method' => 'testNothing',
+ 'message' => "expected: true\nresult: true\n",
+ 'data' => array('expected' => true, 'result' => true),
'file' => realpath($file),
'line' => 14,
- 'method' => 'testNothing',
'assertion' => 'assertTrue',
- 'class' => 'lithium\\tests\\mocks\\test\\MockUnitTest',
- 'message' => "expected: true\nresult: true\n",
- 'data' => array('expected' => true, 'result' => true)
);
$result = $this->test->run();
$this->assertEqual($expected, $result[0]);
@@ -491,6 +493,13 @@ public function testGetTest() {
$this->assertEqual($expected, $result);
}
+ /**
+ * With a fresh PHP environment this might throw an exception:
+ * `strtotime(): It is not safe to rely on the system's timezone settings. You are
+ * *required* to use the date.timezone setting or the date_default_timezone_set() function.`
+ * See also http://www.php.net/manual/en/function.date-default-timezone-get.php
+ * Nuff said...
+ */
public function testAssertCookie() {
$expected = array(
'key' => 'key2.nested', 'value' => 'value1', 'expires' => 'May 04 2010 14:02:36 EST'
@@ -543,10 +552,20 @@ public function testCompareWithEmptyResult() {
public function testExceptionCatching() {
$test = new MockSkipThrowsException();
+ $test->run();
+ $expected = 'skip throws exception';
+ $results = $test->results();
+ $this->assertEqual($expected, $results[0]['message']);
+ $test = new MockSetUpThrowsException();
$test->run();
+ $expected = 'setUp throws exception';
+ $results = $test->results();
+ $this->assertEqual($expected, $results[0]['message']);
- $expected = 'skip throws exception';
+ $test = new MockTearDownThrowsException();
+ $test->run();
+ $expected = 'tearDown throws exception';
$results = $test->results();
$this->assertEqual($expected, $results[0]['message']);
}
@@ -652,6 +671,7 @@ public function testTestMethods() {
$result = $this->test->methods();
$this->assertIdentical($expected, $result);
}
+
}
?>
@@ -0,0 +1,23 @@
+<?php
+/**
+ * Lithium: the most rad php framework
+ *
+ * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+ * @license http://opensource.org/licenses/bsd-license.php The BSD License
+ */
+
+namespace lithium\tests\mocks\test\cases;
+
+class MockSetUpThrowsException extends \lithium\test\Unit {
+
+ public function setUp() {
+ throw new Exception();
+ }
+
+ public function testNothing() {
+ $this->assert(true);
+ }
+
+}
+
+?>
@@ -0,0 +1,24 @@
+<?php
+/**
+ * Lithium: the most rad php framework
+ *
+ * @copyright Copyright 2012, Union of RAD (http://union-of-rad.org)
+ * @license http://opensource.org/licenses/bsd-license.php The BSD License
+ */
+
+namespace lithium\tests\mocks\test\cases;
+
+use Exception;
+
+class MockTearDownThrowsException extends \lithium\test\Unit {
+
+ public function testNothing() {
+ $this->assert(true);
+ }
+
+ public function tearDown() {
+ throw new Exception('tearDown throws exception');
+ }
+}
+
+?>

0 comments on commit 2f7f4db

Please sign in to comment.