Skip to content

Commit

Permalink
fix PHP 8 tests running with wrong --php-version=/phpVersion= if not …
Browse files Browse the repository at this point in the history
…explicitly specified
  • Loading branch information
kkmuffme committed Mar 2, 2024
1 parent 20e8604 commit 7c713e5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 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
10 changes: 9 additions & 1 deletion tests/Traits/InvalidCodeAnalysisTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,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', '<')) {
$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
14 changes: 13 additions & 1 deletion tests/Traits/ValidCodeAnalysisTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,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', '<')) {
$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', '<')) {
$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 7c713e5

Please sign in to comment.