Skip to content

@requires PHP not working with equal sign with minors or majors #213

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

Closed
jrfnl opened this issue Dec 9, 2020 · 2 comments
Closed

@requires PHP not working with equal sign with minors or majors #213

jrfnl opened this issue Dec 9, 2020 · 2 comments

Comments

@jrfnl
Copy link
Contributor

jrfnl commented Dec 9, 2020

Q A
PHPUnit version 9.5.0 (and before)
PHP version All
Installation Method PHAR (but irrelevant)

Summary

Based on the documentation for the @requires tag:

Example: @requires PHP >= 7.2

and

The following operators are supported for PHP, PHPUnit, and extension version constraints: <, <=, >, >=, =, ==, !=, <>.

... I'd expect to be able to use @requires PHP = 7.4 to run a particular test only on PHP 7.4.x, but that doesn't seem to work.

Ref: https://phpunit.readthedocs.io/en/9.5/incomplete-and-skipped-tests.html#skipping-tests-using-requires

Current behavior

Test is always skipped, independently of the PHP version.

How to reproduce

Using PHP 7.4.x, run phpunit RunsOnlyOnPHP74.php where the RunsOnlyOnPHP74.php file contains the below content.
Both tests will be skipped.

<?php

use PHPUnit\Framework\TestCase;

class RunsOnlyOnPHP74 extends TestCase {

    /**
     * @requires PHP = 7.4
     */
    public function testEquals()
    {
        $this->assertTrue(true);
    }

    /**
     * @requires PHP == 7.4
     */
    public function testDoubleEquals()
    {
        $this->assertTrue(true);
    }
}

Expected behavior

That both tests would run on any PHP 7.4 version, but not on any other PHP version.

Additional information

  • Using a specific patch version @requires PHP = 7.4.13 does work, it's only minors and majors which don't.
  • Using @requires PHP 7.4 is not an option as in that case, the test would also be run on PHP 8.0, which is explicitly not the intent.
  • I'm aware I can work-around this by doing a version check within the test in combination with $this->markTestSkipped().
  • This appears never to have worked - I tested with PHPUnit 5 - 9.

If this is just not supported, this could be regarded as a feature request.

If the feature request would be rejected, I'd suggest updating the documentation to make it explicit that this type of use is not supported.

@sebastianbergmann
Copy link
Owner

PHPUnit uses PHP's version_compare() function to implement this functionality:

php > var_dump(PHP_VERSION);
string(6) "7.4.13"
php > var_dump(version_compare(PHP_VERSION, '7.4.13', '='));
bool(true)
php > var_dump(version_compare(PHP_VERSION, '7.4.13', '=='));
bool(true)
php > var_dump(version_compare(PHP_VERSION, '7.4', '='));
bool(false)
php > var_dump(version_compare(PHP_VERSION, '7.4', '=='));
bool(false)
php > var_dump(version_compare(PHP_VERSION, '7.4', '>='));
bool(true)

I agree that the documentation should be updated to reflect this.

@sebastianbergmann sebastianbergmann transferred this issue from sebastianbergmann/phpunit Dec 9, 2020
sebastianbergmann added a commit that referenced this issue Dec 9, 2020
sebastianbergmann added a commit that referenced this issue Dec 9, 2020
@jrfnl
Copy link
Contributor Author

jrfnl commented Dec 9, 2020

PHPUnit uses PHP's version_compare() function to implement this functionality:

@sebastianbergmann I suspected as much ;-) Thanks for getting back to me. Documentation change looks good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants