Skip to content

Commit

Permalink
Merge pull request #10776 from kkmuffme/fix-php8-tests-use-wrong-anal…
Browse files Browse the repository at this point in the history
…ysis-version
  • Loading branch information
weirdan committed Mar 3, 2024
2 parents 9e905ec + 87e2af4 commit b061783
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
4 changes: 2 additions & 2 deletions tests/CoreStubsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ function foo(string $foo): string
'$c3===' => 'bool',
],
];
yield 'PHP8 str_* function assert non-empty-string' => [
yield 'PHP80-str_* function assert non-empty-string' => [
'code' => '<?php
/** @return non-empty-string */
function after_str_contains(): string
Expand Down Expand Up @@ -258,7 +258,7 @@ function after_stripos(): string
'$e===' => 'non-empty-string',
],
];
yield "PHP8 str_* function doesn't subtract string after assertion" => [
yield "PHP80-str_* function doesn't subtract string after assertion" => [
'code' => '<?php
/** @return false|string */
function after_str_contains()
Expand Down
15 changes: 11 additions & 4 deletions tests/Traits/InvalidCodeAnalysisTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
use function strpos;
use function strtoupper;
use function substr;
use function version_compare;

use const PHP_OS;
use const PHP_VERSION;
use const PHP_VERSION_ID;

/**
* @psalm-type DeprecatedDataProviderArrayNotation = array{
Expand Down Expand Up @@ -49,17 +48,25 @@ public function testInvalidCode(
string $code,
string $error_message,
array $error_levels = [],
string $php_version = '7.4'
?string $php_version = null
): void {
$test_name = $this->getTestName();
if (strpos($test_name, 'PHP80-') !== false) {
if (version_compare(PHP_VERSION, '8.0.0', '<')) {
if (PHP_VERSION_ID < 8_00_00) {
$this->markTestSkipped('Test case requires PHP 8.0.');
}

if ($php_version === null) {
$php_version = '8.0';
}
} elseif (strpos($test_name, 'SKIPPED-') !== false) {
$this->markTestSkipped('Skipped due to a bug.');
}

if ($php_version === null) {
$php_version = '7.4';
}

// sanity check - do we have a PHP tag?
if (strpos($code, '<?php') === false) {
$this->fail('Test case must have a <?php tag');
Expand Down
21 changes: 16 additions & 5 deletions tests/Traits/ValidCodeAnalysisTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
use function strpos;
use function strtoupper;
use function substr;
use function version_compare;

use const PHP_OS;
use const PHP_VERSION;
use const PHP_VERSION_ID;

trait ValidCodeAnalysisTestTrait
{
Expand All @@ -40,21 +39,33 @@ public function testValidCode(
string $code,
array $assertions = [],
array $ignored_issues = [],
string $php_version = '7.4'
?string $php_version = null
): void {
$test_name = $this->getTestName();
if (strpos($test_name, 'PHP80-') !== false) {
if (version_compare(PHP_VERSION, '8.0.0', '<')) {
if (PHP_VERSION_ID < 8_00_00) {
$this->markTestSkipped('Test case requires PHP 8.0.');
}

if ($php_version === null) {
$php_version = '8.0';
}
} elseif (strpos($test_name, 'PHP81-') !== false) {
if (version_compare(PHP_VERSION, '8.1.0', '<')) {
if (PHP_VERSION_ID < 8_01_00) {
$this->markTestSkipped('Test case requires PHP 8.1.');
}

if ($php_version === null) {
$php_version = '8.1';
}
} elseif (strpos($test_name, 'SKIPPED-') !== false) {
$this->markTestSkipped('Skipped due to a bug.');
}

if ($php_version === null) {
$php_version = '7.4';
}

// sanity check - do we have a PHP tag?
if (strpos($code, '<?php') === false) {
$this->fail('Test case must have a <?php tag');
Expand Down

0 comments on commit b061783

Please sign in to comment.