forked from nette/tester
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TestCase: annotation @throws is applied to testMethods() only, not to…
… setUp() nor tearDown() (BC break) [Closes nette#238] BC break: default value of runTest() 2nd parameter is NULL, empty array bypasses dataprovider BC break: runTest() now takes into account a @throws annotation, so expected exception is caught, not thrown BC break: runTest() now run for all dataprovider records
- Loading branch information
Showing
2 changed files
with
150 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
tests/Framework/TestCase.annotationThrows.setUp.tearDown.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
|
||
use Tester\Assert; | ||
use Tester\TestCase; | ||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
class SuccessTestCase extends TestCase | ||
{ | ||
/** @throws Exception SuccessTestCase::testMe */ | ||
public function testMe() | ||
{ | ||
throw new Exception(__METHOD__); | ||
} | ||
} | ||
|
||
$test = new SuccessTestCase; | ||
$test->run(); | ||
|
||
|
||
|
||
class FailingTestCase extends TestCase | ||
{ | ||
/** @throws RuntimeException Wrong message */ | ||
public function testMe() | ||
{ | ||
throw new Exception(__METHOD__); | ||
} | ||
} | ||
|
||
Assert::exception(function () { | ||
$test = new FailingTestCase; | ||
$test->run(); | ||
}, 'Tester\AssertException', 'RuntimeException was expected but got Exception (FailingTestCase::testMe) in testMe()'); | ||
|
||
|
||
|
||
class SuccessButSetUpFails extends SuccessTestCase | ||
{ | ||
public function setUp() | ||
{ | ||
throw new Exception(__METHOD__); | ||
} | ||
} | ||
|
||
Assert::exception(function () { | ||
$test = new SuccessButSetUpFails; | ||
$test->run(); | ||
}, 'Exception', 'SuccessButSetUpFails::setUp'); | ||
|
||
|
||
|
||
class SuccessButTearDownFails extends SuccessTestCase | ||
{ | ||
public function tearDown() | ||
{ | ||
throw new Exception(__METHOD__); | ||
} | ||
} | ||
|
||
Assert::exception(function () { | ||
$test = new SuccessButTearDownFails; | ||
$test->run(); | ||
}, 'Exception', 'SuccessButTearDownFails::tearDown'); | ||
|
||
|
||
|
||
class FailingAndSetUpFails extends FailingTestCase | ||
{ | ||
public function setUp() | ||
{ | ||
throw new Exception(__METHOD__); | ||
} | ||
} | ||
|
||
Assert::exception(function () { | ||
$test = new FailingAndSetUpFails; | ||
$test->run(); | ||
}, 'Exception', 'FailingAndSetUpFails::setUp'); | ||
|
||
|
||
|
||
class FailingAndTearDownFails extends FailingTestCase | ||
{ | ||
public function tearDown() | ||
{ | ||
throw new Exception(__METHOD__); | ||
} | ||
} | ||
|
||
// tearDown() exception is never thrown when @throws assertion fails | ||
Assert::exception(function () { | ||
$test = new FailingAndTearDownFails; | ||
$test->run(); | ||
}, 'Tester\AssertException', 'RuntimeException was expected but got Exception (FailingTestCase::testMe) in testMe()'); |