Skip to content

Commit c0929f9

Browse files
phpstan-botclaude
authored andcommitted
Split DateInterval test expectations by PHP version
On PHP < 8.1, DateInterval::__construct() prefixes the exception message with "DateInterval::__construct(): ", while PHP 8.1+ uses a shorter format. Gate the existing test with RequiresPhp(>= 8.1.0) and add a separate testLegacyPhp method for older PHP versions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8dc3791 commit c0929f9

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

tests/PHPStan/Rules/DateIntervalInstantiationRuleTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace PHPStan\Rules;
44

55
use PHPStan\Testing\RuleTestCase;
6+
use PHPUnit\Framework\Attributes\RequiresPhp;
67

78
/**
89
* @extends RuleTestCase<DateIntervalInstantiationRule>
@@ -15,6 +16,7 @@ protected function getRule(): Rule
1516
return new DateIntervalInstantiationRule();
1617
}
1718

19+
#[RequiresPhp('>= 8.1.0')]
1820
public function test(): void
1921
{
2022
$this->analyse(
@@ -44,4 +46,34 @@ public function test(): void
4446
);
4547
}
4648

49+
#[RequiresPhp('< 8.1.0')]
50+
public function testLegacyPhp(): void
51+
{
52+
$this->analyse(
53+
[__DIR__ . '/data/date-interval-instantiation.php'],
54+
[
55+
[
56+
'Instantiating DateInterval with 1M produces an error: DateInterval::__construct(): Unknown or bad format (1M)',
57+
5,
58+
],
59+
[
60+
'Instantiating DateInterval with asdfasdf produces an error: DateInterval::__construct(): Unknown or bad format (asdfasdf)',
61+
18,
62+
],
63+
[
64+
'Instantiating DateInterval with produces an error: DateInterval::__construct(): Unknown or bad format ()',
65+
21,
66+
],
67+
[
68+
'Instantiating DateInterval with 1M produces an error: DateInterval::__construct(): Unknown or bad format (1M)',
69+
30,
70+
],
71+
[
72+
'Instantiating DateInterval with invalid produces an error: DateInterval::__construct(): Unknown or bad format (invalid)',
73+
37,
74+
],
75+
],
76+
);
77+
}
78+
4779
}

0 commit comments

Comments
 (0)