diff --git a/src/Framework/TestCase.php b/src/Framework/TestCase.php index 487a3f0ef32..6a4e3057e4c 100755 --- a/src/Framework/TestCase.php +++ b/src/Framework/TestCase.php @@ -806,7 +806,9 @@ public function runBare() $hookMethods = PHPUnit_Util_Test::getHookMethods(get_class($this)); try { + $hasRequirements = false; $this->checkRequirements(); + $hasRequirements = true; if ($this->inIsolation) { foreach ($hookMethods['beforeClass'] as $method) { @@ -845,14 +847,16 @@ public function runBare() // Tear down the fixture. An exception raised in tearDown() will be // caught and passed on when no exception was raised before. try { - foreach ($hookMethods['after'] as $method) { - $this->$method(); - } - - if ($this->inIsolation) { - foreach ($hookMethods['afterClass'] as $method) { + if ($hasRequirements) { + foreach ($hookMethods['after'] as $method) { $this->$method(); } + + if ($this->inIsolation) { + foreach ($hookMethods['afterClass'] as $method) { + $this->$method(); + } + } } } catch (Exception $_e) { if (!isset($e)) { diff --git a/tests/Regression/GitHub/1374.phpt b/tests/Regression/GitHub/1374.phpt new file mode 100644 index 00000000000..9ec7e3c7961 --- /dev/null +++ b/tests/Regression/GitHub/1374.phpt @@ -0,0 +1,21 @@ +--TEST-- +GH-1374: tearDown() is called despite unmet requirements +--FILE-- + +--EXPECTF-- +PHPUnit %s by Sebastian Bergmann. + +S + +Time: %s, Memory: %sMb + +OK, but incomplete, skipped, or risky tests! +Tests: 1, Assertions: 0, Skipped: 1. diff --git a/tests/Regression/GitHub/1374/Issue1374Test.php b/tests/Regression/GitHub/1374/Issue1374Test.php new file mode 100644 index 00000000000..ad6a3bf090e --- /dev/null +++ b/tests/Regression/GitHub/1374/Issue1374Test.php @@ -0,0 +1,21 @@ +fail('This should not be reached'); + } + + protected function tearDown() + { + print __FUNCTION__; + } +}