Skip to content

Commit b5c1c72

Browse files
committed
Add tests for thrown DateMalformedIntervalStringException
1 parent 014a349 commit b5c1c72

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

tests/PHPStan/Rules/Exceptions/CatchWithUnthrownExceptionRuleTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ public function testRule(): void
141141
'Dead catch - ArithmeticError is never thrown in the try block.',
142142
762,
143143
],
144+
[
145+
'Dead catch - DateMalformedIntervalStringException is never thrown in the try block.',
146+
800,
147+
],
144148
]);
145149
}
146150

@@ -233,6 +237,10 @@ public function testRuleWithoutReportingUncheckedException(): void
233237
'Dead catch - Exception is never thrown in the try block.',
234238
555,
235239
],
240+
[
241+
'Dead catch - DateMalformedIntervalStringException is never thrown in the try block.',
242+
800,
243+
],
236244
]);
237245
}
238246

tests/PHPStan/Rules/Exceptions/data/unthrown-exception.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,3 +790,24 @@ public function doFoo(int $int, int $negativeInt, int $positiveInt): void
790790
}
791791

792792
}
793+
794+
class TestDateIntervalCreateFromDateString
795+
{
796+
public function doFoo(): void
797+
{
798+
try {
799+
\DateInterval::createFromDateString('P10D');
800+
} catch (\DateMalformedIntervalStringException $e) {
801+
802+
}
803+
}
804+
805+
public function doBar(): void
806+
{
807+
try {
808+
\DateInterval::createFromDateString('invalid');
809+
} catch (\DateMalformedIntervalStringException $e) {
810+
811+
}
812+
}
813+
}

0 commit comments

Comments
 (0)