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.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
3 changed files
with
157 additions
and
3 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
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,100 @@ | ||
<?php | ||
|
||
use Tester\Assert; | ||
|
||
require __DIR__ . '/bootstrap.php'; | ||
|
||
|
||
class MyException extends Exception | ||
{ | ||
} | ||
|
||
class MyTest extends Tester\TestCase | ||
{ | ||
/** @throws Exception */ | ||
public function testThrows() | ||
{ | ||
throw new Exception; | ||
} | ||
|
||
/** @throws Exception */ | ||
public function testThrowsButDont() | ||
{ | ||
} | ||
|
||
/** @throws Exception With message */ | ||
public function testThrowsMessage() | ||
{ | ||
throw new Exception('With message'); | ||
} | ||
|
||
/** @throws Exception */ | ||
public function testFailAssertPass() | ||
{ | ||
Assert::fail('failed'); | ||
} | ||
|
||
/** @throws MyException */ | ||
public function testThrowsBadClass() | ||
{ | ||
throw new Exception; | ||
} | ||
|
||
/** @throws Exception With message */ | ||
public function testThrowsBadMessage() | ||
{ | ||
throw new Exception('Bad message'); | ||
} | ||
|
||
// Without @throws | ||
public function testWithoutThrows() | ||
{ | ||
throw new Exception; | ||
} | ||
|
||
public function dataProvider() | ||
{ | ||
return array(array(1)); | ||
} | ||
|
||
/** | ||
* @dataprovider dataProvider | ||
* @throws Exception | ||
*/ | ||
public function testThrowsWithDataprovider($x) | ||
{ | ||
} | ||
} | ||
|
||
|
||
$test = new MyTest; | ||
$test->run('testThrows'); | ||
$test->run('testThrowsMessage'); | ||
|
||
Assert::exception(function() use ($test) { | ||
$test->run('testThrowsButDont'); | ||
}, 'Tester\AssertException', 'Exception was expected, but none was thrown in testThrowsButDont()'); | ||
|
||
Assert::exception(function() use ($test) { | ||
$test->run('testFailAssertPass'); | ||
}, 'Tester\AssertException', 'failed in testFailAssertPass()'); | ||
|
||
Assert::exception(function() use ($test) { | ||
$test->run('testThrowsBadClass'); | ||
}, 'Tester\AssertException', 'MyException was expected but got Exception in testThrowsBadClass()'); | ||
|
||
Assert::exception(function() use ($test) { | ||
$test->run('testThrowsBadMessage'); | ||
}, 'Tester\AssertException', "Exception with a message matching 'With message' was expected but got 'Bad message' in testThrowsBadMessage()"); | ||
|
||
Assert::exception(function() use ($test) { | ||
$test->run('testWithoutThrows'); | ||
}, 'Exception'); | ||
|
||
Assert::exception(function() use ($test) { | ||
$test->run('testThrowsWithDataprovider'); | ||
}, 'Exception', 'Exception was expected, but none was thrown in testThrowsWithDataprovider(1)'); | ||
|
||
Assert::exception(function() use ($test) { | ||
$test->run('testUndefinedMethod'); | ||
}, 'ReflectionException', 'Method testUndefinedMethod does not exist'); |
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,35 @@ | ||
<?php | ||
|
||
use Tester\Assert; | ||
|
||
require __DIR__ . '/bootstrap.php'; | ||
|
||
|
||
class MyTest extends Tester\TestCase | ||
{ | ||
/** | ||
* @throws | ||
*/ | ||
public function testThrowsNoClass() | ||
{ | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
* @throws Exception | ||
*/ | ||
public function testThrowsMultiple() | ||
{ | ||
} | ||
|
||
} | ||
|
||
$test = new MyTest; | ||
|
||
Assert::exception(function() use ($test) { | ||
$test->run('testThrowsNoClass'); | ||
}, 'Tester\TestCaseException', 'Missing class name in @throws annotation for testThrowsNoClass().'); | ||
|
||
Assert::exception(function() use ($test) { | ||
$test->run('testThrowsMultiple'); | ||
}, 'Tester\TestCaseException', 'Annotation @throws for testThrowsMultiple() can be specified only once.'); |