-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path07ExceptionWithMsgAndCode.php
More file actions
47 lines (43 loc) · 1.47 KB
/
07ExceptionWithMsgAndCode.php
File metadata and controls
47 lines (43 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
/**
* This class will test the (exception,msg) and (exception,code)
*/
class ExceptionWithMsgAndCodeTest extends PHPUnit_Framework_TestCase
{
/**
* If a function is written to test exception and its msg then it should be
* mentioned as a comment tag in method comment as 'expectedException' and
* 'expectedExceptionMessage'
*
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Right Message
*/
public function testExceptionHasRightMessage()
{
$exception = new AbcException("hello" , 20 );
#$exception = new InvalidArgumentException('Right Message', 10);
// Uncommenting above line will pass this test
throw $exception;
}
/**
* If a function is written to test exception and its msg then it should be
* mentioned as a comment tag in method comment as 'expectedException' and
* 'expectedExceptionCode'
*
* @expectedException InvalidArgumentException
* @expectedExceptionCode 20
*/
public function testExceptionHasRightCode()
{
$exception = new AbcException("hello" , 20 );
#$exception = new InvalidArgumentException('Right Message', 20);
// Uncommenting above line will pass this test
throw $exception;
}
}
class AbcException extends Exception{
public function __construct($message, $code, $previous = null) {
parent::__construct($message, $code, $previous);
}
}
?>