Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #536 from hans-d/fix_teardown

On exception from tearDown pass/fail is not reported
  • Loading branch information...
commit e7f83a781206423288bf6334fb3be6eb3142e4ab 2 parents a715901 + 4c66158
Nate Abele nateabele authored
28 tests/cases/test/UnitTest.php
View
@@ -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,12 @@ 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
+ */
public function testAssertCookie() {
$expected = array(
'key' => 'key2.nested', 'value' => 'value1', 'expires' => 'May 04 2010 14:02:36 EST'
@@ -543,10 +551,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']);
}
25 tests/mocks/test/cases/MockSetUpThrowsException.php
View
@@ -0,0 +1,25 @@
+<?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 MockSetUpThrowsException extends \lithium\test\Unit {
+
+ public function setUp() {
+ throw new Exception('setUp throws exception');
+ }
+
+ public function testNothing() {
+ $this->assert(true);
+ }
+
+}
+
+?>
24 tests/mocks/test/cases/MockTearDownThrowsException.php
View
@@ -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');
+ }
+}
+
+?>
Please sign in to comment.
Something went wrong with that request. Please try again.