Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix PHP 8 tests running with wrong --php-version=/phpVersion= if not explicitly specified #10776

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/CoreStubsTest.php
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
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
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