|
14 | 14 |
|
15 | 15 | final class ExpectingExceptionsTest extends TestCase |
16 | 16 | { |
17 | | - public function testPassesWhenExpectedExceptionIsThrown(): void |
| 17 | + public function test_expectException_and_expected_exception_is_thrown(): void |
18 | 18 | { |
19 | 19 | $this->expectException(Exception::class); |
20 | 20 |
|
21 | 21 | throw new Exception; |
22 | 22 | } |
23 | 23 |
|
24 | | - public function testFailsWhenExpectedExceptionIsNotThrown(): void |
| 24 | + public function test_expectException_and_expected_exception_is_not_thrown(): void |
25 | 25 | { |
26 | 26 | $this->expectException(Exception::class); |
27 | 27 | } |
28 | 28 |
|
29 | | - public function testPassesWhenExpectedExceptionIsThrownAndHasMessageThatIsOrContainsExpectedMessage(): void |
| 29 | + public function test_expectException_and_expectExceptionMessage_and_expected_exception_is_thrown_and_has_expected_message(): void |
30 | 30 | { |
31 | 31 | $this->expectException(Exception::class); |
32 | 32 | $this->expectExceptionMessage('message'); |
33 | 33 |
|
34 | 34 | throw new Exception('message'); |
35 | 35 | } |
36 | 36 |
|
37 | | - public function testFailsWhenExpectedExceptionIsThrownAndDoesNotHaveMessageThatIsOrContainsExpectedMessage(): void |
| 37 | + public function test_expectExceptionMessage_and_exception_is_thrown_and_has_expected_message(): void |
| 38 | + { |
| 39 | + $this->expectExceptionMessage('message'); |
| 40 | + |
| 41 | + throw new Exception('message'); |
| 42 | + } |
| 43 | + |
| 44 | + public function test_expectException_and_expectExceptionMessage_and_expected_exception_is_thrown_but_does_not_have_expected_message(): void |
38 | 45 | { |
39 | 46 | $this->expectException(Exception::class); |
40 | 47 | $this->expectExceptionMessage('message'); |
41 | 48 |
|
42 | 49 | throw new Exception; |
43 | 50 | } |
44 | 51 |
|
45 | | - public function testPassesWhenExpectedExceptionIsThrownAndHasMessageThatMatchesRegularExpression(): void |
| 52 | + public function test_expectExceptionMessage_and_exception_is_thrown_but_does_not_have_expected_message(): void |
| 53 | + { |
| 54 | + $this->expectExceptionMessage('message'); |
| 55 | + |
| 56 | + throw new Exception; |
| 57 | + } |
| 58 | + |
| 59 | + public function test_expectExceptionMessage_and_no_exception_is_thrown(): void |
| 60 | + { |
| 61 | + $this->expectExceptionMessage('message'); |
| 62 | + } |
| 63 | + |
| 64 | + public function test_expectException_and_expectExceptionMessageMatches_and_expected_exception_is_thrown_and_has_expected_message(): void |
46 | 65 | { |
47 | 66 | $this->expectException(Exception::class); |
48 | 67 | $this->expectExceptionMessageMatches('/message/'); |
49 | 68 |
|
50 | 69 | throw new Exception('message'); |
51 | 70 | } |
52 | 71 |
|
53 | | - public function testFailsWhenExpectedExceptionIsThrownAndDoesNotHaveMessageThatMatchesRegularExpression(): void |
| 72 | + public function test_expectExceptionMessageMatches_and_exception_is_thrown_and_has_expected_message(): void |
| 73 | + { |
| 74 | + $this->expectExceptionMessageMatches('/message/'); |
| 75 | + |
| 76 | + throw new Exception('message'); |
| 77 | + } |
| 78 | + |
| 79 | + public function test_expectException_and_expectExceptionMessageMatches_and_expected_exception_is_thrown_but_does_not_have_expected_message(): void |
54 | 80 | { |
55 | 81 | $this->expectException(Exception::class); |
56 | 82 | $this->expectExceptionMessageMatches('/message/'); |
57 | 83 |
|
58 | 84 | throw new Exception; |
59 | 85 | } |
60 | 86 |
|
61 | | - public function testPassesWhenExpectedExceptionIsThrownAndHasExpectedCode(): void |
| 87 | + public function test_expectExceptionMessageMatches_and_exception_is_thrown_but_does_not_have_expected_message(): void |
| 88 | + { |
| 89 | + $this->expectExceptionMessageMatches('/message/'); |
| 90 | + |
| 91 | + throw new Exception; |
| 92 | + } |
| 93 | + |
| 94 | + public function test_expectExceptionMessageMatches_and_no_exception_is_thrown(): void |
| 95 | + { |
| 96 | + $this->expectExceptionMessageMatches('/message/'); |
| 97 | + } |
| 98 | + |
| 99 | + public function test_expectException_and_expectExceptionCode_and_expected_exception_is_thrown_and_has_expected_code(): void |
62 | 100 | { |
63 | 101 | $this->expectException(Exception::class); |
64 | 102 | $this->expectExceptionCode(1234); |
65 | 103 |
|
66 | 104 | throw new Exception(code: 1234); |
67 | 105 | } |
68 | 106 |
|
69 | | - public function testFailsWhenExpectedExceptionIsThrownAndDoesNotHaveExpectedCode(): void |
| 107 | + public function test_expectExceptionCode_and_exception_is_thrown_and_has_expected_code(): void |
| 108 | + { |
| 109 | + $this->expectExceptionCode(1234); |
| 110 | + |
| 111 | + throw new Exception(code: 1234); |
| 112 | + } |
| 113 | + |
| 114 | + public function test_expectException_and_expectExceptionCode_and_expected_exception_is_thrown_but_does_not_have_expected_code(): void |
70 | 115 | { |
71 | 116 | $this->expectException(Exception::class); |
72 | 117 | $this->expectExceptionCode(1234); |
73 | 118 |
|
74 | 119 | throw new Exception; |
75 | 120 | } |
76 | 121 |
|
77 | | - public function testPassesWhenExpectedExceptionObjectIsThrown(): void |
| 122 | + public function test_expectExceptionCode_and_exception_is_thrown_but_does_not_have_expected_code(): void |
| 123 | + { |
| 124 | + $this->expectExceptionCode(1234); |
| 125 | + |
| 126 | + throw new Exception; |
| 127 | + } |
| 128 | + |
| 129 | + public function test_expectExceptionCode_and_no_exception_is_thrown(): void |
| 130 | + { |
| 131 | + $this->expectExceptionCode(1234); |
| 132 | + } |
| 133 | + |
| 134 | + public function test_expectExceptionObject_and_expected_exception_is_thrown(): void |
78 | 135 | { |
79 | 136 | $this->expectExceptionObject(new Exception('message', 1234)); |
80 | 137 |
|
81 | 138 | throw new Exception('message', 1234); |
82 | 139 | } |
83 | 140 |
|
84 | | - public function testFailsWhenExpectedExceptionObjectIsNotThrown(): void |
| 141 | + public function test_expectExceptionObject_and_expected_exception_is_not_thrown(): void |
| 142 | + { |
| 143 | + $this->expectExceptionObject(new Exception('message', 1234)); |
| 144 | + |
| 145 | + throw new Exception('not-the-message', 5678); |
| 146 | + } |
| 147 | + |
| 148 | + public function test_expectExceptionObject_and_no_exception_is_thrown(): void |
85 | 149 | { |
86 | 150 | $this->expectExceptionObject(new Exception('message', 1234)); |
87 | 151 | } |
|
0 commit comments