Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

On exception from tearDown pass/fail is not reported #536

Merged
merged 4 commits into from

2 participants

@hans-d

When an exception is thrown in 'tearDown`, the results of the asserts in the method directly preceding the tearDown are not displayed and not taken into account of the total tests(asserts) being run.

Note: Also had to swap the lines in testRun to make UnitTest pass (prior to making other changes).

hans-d added some commits
@hans-d hans-d 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
2f7f4db
@hans-d hans-d fix SetupThrowsExceptions. This test passes already. 7455a62
@hans-d

In the testcase in the example, UnitTest reports: UniTest reports: 91 / 91 passes, 0 fails and 1 exception.
This should be 92 / 92 passes, 0 fails and 1 exception.

@hans-d

Also $this->expectException() is not found in the results (non-verbose dots, verbose passing line, totals x / x passes).

tests/cases/test/UnitTest.php
@@ -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...
@nateabele Owner

A comment like "Nuff said..." is fine in discussions on GitHub issues, but not appropriate in the source code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
tests/cases/test/UnitTest.php
@@ -652,6 +671,7 @@ public function testTestMethods() {
$result = $this->test->methods();
$this->assertIdentical($expected, $result);
}
+
@nateabele Owner

Why the extra line break here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@hans-d

Remarks processed...

@nateabele
Owner

Perfect, thanks!

@nateabele nateabele merged commit e7f83a7 into from
@hans-d

@nateabele, please do note that the underlying issue (displayed number of tests run/passed/failed) is still not solved in this one...

@nateabele
Owner

Right, I understand. It's okay for PRs that produce failing test cases to go to dev. Once someone's able to get a patch to dev that makes the tests pass, then we'll merge to master.

@gwoo gwoo referenced this pull request from a commit
@gwoo gwoo Going green after #536 where test cases were added to test exception …
…handling in test cases.
d4ae2a6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 12, 2012
  1. @hans-d

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

    hans-d authored
    … 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
  2. @hans-d
Commits on Jun 14, 2012
  1. @hans-d
  2. @hans-d
This page is out of date. Refresh to see the latest.
View
28 tests/cases/test/UnitTest.php
@@ -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']);
}
View
25 tests/mocks/test/cases/MockSetUpThrowsException.php
@@ -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);
+ }
+
+}
+
+?>
View
24 tests/mocks/test/cases/MockTearDownThrowsException.php
@@ -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');
+ }
+}
+
+?>
Something went wrong with that request. Please try again.