Skip to content

Commit 2c49ccb

Browse files
Merge branch '12.5'
* 12.5: Add tests Ignore code from code coverage for handling of edge case that I do not know how to test
2 parents 8b18a30 + fabdf63 commit 2c49ccb

File tree

3 files changed

+105
-18
lines changed

3 files changed

+105
-18
lines changed

src/Util/Xml/Loader.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ public function load(string $actual): DOMDocument
8181

8282
if ($loaded === false) {
8383
if ($message === '') {
84+
// @codeCoverageIgnoreStart
8485
$message = 'Could not load XML for unknown reason';
86+
// @codeCoverageIgnoreEnd
8587
}
8688

8789
throw new XmlException($message);

tests/end-to-end/_files/ExpectingExceptionsTest.php

Lines changed: 74 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,74 +14,138 @@
1414

1515
final class ExpectingExceptionsTest extends TestCase
1616
{
17-
public function testPassesWhenExpectedExceptionIsThrown(): void
17+
public function test_expectException_and_expected_exception_is_thrown(): void
1818
{
1919
$this->expectException(Exception::class);
2020

2121
throw new Exception;
2222
}
2323

24-
public function testFailsWhenExpectedExceptionIsNotThrown(): void
24+
public function test_expectException_and_expected_exception_is_not_thrown(): void
2525
{
2626
$this->expectException(Exception::class);
2727
}
2828

29-
public function testPassesWhenExpectedExceptionIsThrownAndHasMessageThatIsOrContainsExpectedMessage(): void
29+
public function test_expectException_and_expectExceptionMessage_and_expected_exception_is_thrown_and_has_expected_message(): void
3030
{
3131
$this->expectException(Exception::class);
3232
$this->expectExceptionMessage('message');
3333

3434
throw new Exception('message');
3535
}
3636

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
3845
{
3946
$this->expectException(Exception::class);
4047
$this->expectExceptionMessage('message');
4148

4249
throw new Exception;
4350
}
4451

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
4665
{
4766
$this->expectException(Exception::class);
4867
$this->expectExceptionMessageMatches('/message/');
4968

5069
throw new Exception('message');
5170
}
5271

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
5480
{
5581
$this->expectException(Exception::class);
5682
$this->expectExceptionMessageMatches('/message/');
5783

5884
throw new Exception;
5985
}
6086

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
62100
{
63101
$this->expectException(Exception::class);
64102
$this->expectExceptionCode(1234);
65103

66104
throw new Exception(code: 1234);
67105
}
68106

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
70115
{
71116
$this->expectException(Exception::class);
72117
$this->expectExceptionCode(1234);
73118

74119
throw new Exception;
75120
}
76121

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
78135
{
79136
$this->expectExceptionObject(new Exception('message', 1234));
80137

81138
throw new Exception('message', 1234);
82139
}
83140

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
85149
{
86150
$this->expectExceptionObject(new Exception('message', 1234));
87151
}

tests/end-to-end/generic/expecting-exceptions.phpt

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,47 @@ PHPUnit %s by Sebastian Bergmann and contributors.
1313

1414
Runtime: %s
1515

16-
.F.F.F.F.F 10 / 10 (100%)
16+
.F..FFF..FFF..FFF.FF 20 / 20 (100%)
1717

1818
Time: %s, Memory: %s
1919

20-
There were 5 failures:
20+
There were 12 failures:
2121

22-
1) PHPUnit\TestFixture\ExpectingExceptionsTest::testFailsWhenExpectedExceptionIsNotThrown
22+
1) PHPUnit\TestFixture\ExpectingExceptionsTest::test_expectException_and_expected_exception_is_not_thrown
2323
Failed asserting that exception of type "Exception" is thrown.
2424

25-
2) PHPUnit\TestFixture\ExpectingExceptionsTest::testFailsWhenExpectedExceptionIsThrownAndDoesNotHaveMessageThatIsOrContainsExpectedMessage
25+
2) PHPUnit\TestFixture\ExpectingExceptionsTest::test_expectException_and_expectExceptionMessage_and_expected_exception_is_thrown_but_does_not_have_expected_message
2626
Failed asserting that exception message '' contains 'message'.
2727

28-
3) PHPUnit\TestFixture\ExpectingExceptionsTest::testFailsWhenExpectedExceptionIsThrownAndDoesNotHaveMessageThatMatchesRegularExpression
28+
3) PHPUnit\TestFixture\ExpectingExceptionsTest::test_expectExceptionMessage_and_exception_is_thrown_but_does_not_have_expected_message
29+
Failed asserting that exception message '' contains 'message'.
30+
31+
4) PHPUnit\TestFixture\ExpectingExceptionsTest::test_expectExceptionMessage_and_no_exception_is_thrown
32+
Failed asserting that exception with message "message" is thrown
33+
34+
5) PHPUnit\TestFixture\ExpectingExceptionsTest::test_expectException_and_expectExceptionMessageMatches_and_expected_exception_is_thrown_but_does_not_have_expected_message
35+
Failed asserting that exception message '' matches '/message/'.
36+
37+
6) PHPUnit\TestFixture\ExpectingExceptionsTest::test_expectExceptionMessageMatches_and_exception_is_thrown_but_does_not_have_expected_message
2938
Failed asserting that exception message '' matches '/message/'.
3039

31-
4) PHPUnit\TestFixture\ExpectingExceptionsTest::testFailsWhenExpectedExceptionIsThrownAndDoesNotHaveExpectedCode
40+
7) PHPUnit\TestFixture\ExpectingExceptionsTest::test_expectExceptionMessageMatches_and_no_exception_is_thrown
41+
Failed asserting that exception with message matching "/message/" is thrown
42+
43+
8) PHPUnit\TestFixture\ExpectingExceptionsTest::test_expectException_and_expectExceptionCode_and_expected_exception_is_thrown_but_does_not_have_expected_code
44+
Failed asserting that 0 is equal to expected exception code 1234.
45+
46+
9) PHPUnit\TestFixture\ExpectingExceptionsTest::test_expectExceptionCode_and_exception_is_thrown_but_does_not_have_expected_code
3247
Failed asserting that 0 is equal to expected exception code 1234.
3348

34-
5) PHPUnit\TestFixture\ExpectingExceptionsTest::testFailsWhenExpectedExceptionObjectIsNotThrown
49+
10) PHPUnit\TestFixture\ExpectingExceptionsTest::test_expectExceptionCode_and_no_exception_is_thrown
50+
Failed asserting that exception with code "1234" is thrown
51+
52+
11) PHPUnit\TestFixture\ExpectingExceptionsTest::test_expectExceptionObject_and_expected_exception_is_not_thrown
53+
Failed asserting that 5678 is equal to expected exception code 1234.
54+
55+
12) PHPUnit\TestFixture\ExpectingExceptionsTest::test_expectExceptionObject_and_no_exception_is_thrown
3556
Failed asserting that exception of type "Exception" is thrown.
3657

3758
FAILURES!
38-
Tests: 10, Assertions: 18, Failures: 5.
59+
Tests: 20, Assertions: 30, Failures: 12.

0 commit comments

Comments
 (0)