WordPress / phpunit-test-runner

GNU General Public License v2.0
68 stars 64 forks source link

Could not open input file: phpunit.phar #149

Closed rafalkukla closed 3 years ago

rafalkukla commented 3 years ago

Hi there,

I am new here. After setting up the environment file for the first time, I run the following command: php prepare.php

and I had expected output:

Success: Prepared environment.

Then I run: php test.php

And at the end of the test I have this error message:

Could not open input file: phpunit.phar
Error: Failed to perform operation.

Tried to Google, but can't find any reference to this.

pfefferle commented 3 years ago

It seems that phpunit.phar is not where it should be. Can you check the folder you defined for the prepare, for the phpunit.phar file (should be $WPT_PREPARE_DIR . '/phpunit.phar')?

rafalkukla commented 3 years ago

Hi @pfefferle Thank you. I set export WPT_TEST_DIR=$WPT_PREPARE_DIR as per documentation and example. Shall I try with $WPT_PREPARE_DIR . '/phpunit.phar'

rafalkukla commented 3 years ago

If I set the path as you suggested $WPT_PREPARE_DIR . '/phpunit.phar' gives me errors

bash: export: `.': not a valid identifier
bash: export: `/phpunit.phar': not a valid identifier
pfefferle commented 3 years ago

Sorry, I think you got me wrong. $WPT_PREPARE_DIR . '/phpunit.phar' is the reference in the code. It means that it tries to run the phpunit.phar in the directory, you set with export, for example export WPT_TEST_DIR=/temp. Then you can check if phpunit.phar is correctly installed in /temp (or whatever path you set).

rafalkukla commented 3 years ago

Hi @pfefferle

If I set path to anything other than $WPT_PREPARE_DIR in the .env file and then run php prepare.php

Error: WPT_TEST_DIR must be the same as WPT_PREPARE_DIR when running locally.

pfefferle commented 3 years ago

Sorry for confusing you, I just wanted to tell you, where you have to search for the phpunit.phar file. Please use the same path for WPT_TEST_DIR and WPT_PREPARE_DIR

rafalkukla commented 3 years ago

Sorry for misunderstand you. I though you were suggesting changing the export path.

Looking at the test output - It start with cd /wordpress' && php ./vendor/phpunit/phpunit/phpunit || php phpunit.phar

Would this mean is correctly installed? Because is executed?

pfefferle commented 3 years ago

do you still get the error?

rafalkukla commented 3 years ago

Yes, at the end of the test.

Could not open input file: phpunit.phar
Error: Failed to perform operation.
rafalkukla commented 3 years ago

This PR has solved my problem - https://github.com/WordPress/phpunit-test-runner/pull/137/files Thank you @pfefferle for your help!

KarlAustin commented 3 years ago

I have this same error, I'm not sure how the referenced PR would fix it (and I'm running latest anyway, so it hasn't).

I would wager the issue stems from an assumption somewhere, because prepare.php has this code:

`// If PHP version is 5.6-7.0, download PHPUnit 5.7 phar directly. if ( version_compare( $env_php_version, '7.1', '<' ) ) { perform_operations( array( 'wget -O ' . escapeshellarg( $WPT_PREPARE_DIR . '/phpunit.phar' ) . ' https://phar.phpunit.de/phpunit-5.7.phar', ) );

// Otherwise, use Composer to download PHPUnit to get further necessary dependencies. } else {

    // First, check if composer is available. Download if not.
    $composer_cmd = 'cd ' . escapeshellarg( $WPT_PREPARE_DIR ) . ' && ';

    $retval = 0;
    $composer_path = escapeshellarg( system( 'which composer', $retval ) );
    if ( $retval === 0 ) {
            $composer_cmd .= $composer_path . ' ';
    } else {
            log_message( 'Local Composer not found. Downloading latest stable ...' );

            perform_operations( array(
                    'wget -O ' . escapeshellarg( $WPT_PREPARE_DIR . '/composer.phar' ) . ' https://getcomposer.org/composer-stable.phar',
            ) );

            $composer_cmd .= 'php composer.phar ';
    }

    // Set Composer PHP environment, then run Composer.
    perform_operations( array(
            $composer_cmd . 'config platform.php ' . escapeshellarg( $env_php_version ),
            $composer_cmd . 'update',
    ) );

} `

So if you're running PHP > 7.0 then phpunit.phar will never exist, as the correct call is via: vendor/phpunit/phpunit/phpunit or 'vendor/bin/phpunit' (symlink)

I haven't been able to work out where this anomalous call to phpunit.phar is coming from though so far.

I thought a quick hack solution would be to create a symlink from phpunit.phar to vendor/phpunit/phpunit/phpunit but now I just get:

Error: Failed to perform operation.

instead of:

Could not open input file: phpunit.phar

It doesn't appear to be a hinderance to report.php being run, but still something is going on somewhere that seems to be broken.

Thanks.