Yoast / PHPUnit-Polyfills

Set of polyfills for changed PHPUnit functionality to allow for creating PHPUnit cross-version compatible tests
BSD 3-Clause "New" or "Revised" License
173 stars 13 forks source link

Github actions no longer work for me. #125

Closed nextgenthemes closed 1 year ago

nextgenthemes commented 1 year ago

Workflow file: https://github.com/nextgenthemes/advanced-responsive-video-embedder/blob/master/.github/workflows/test-deploy.yml

It worked previously and I do not know what is going wrong now. The readme should refer to some basic project that actually uses it as reference IMO, that actually tests it. Not sure what is specific about my setup.

For php 5.6 it runs from the vendor directly in my plugin I find that strange ...

Run phpunit --testsuite arve,arve-pro,arve-random-video,arve-amp,arve-sticky-videos
PHP Warning:  Unsupported declare 'strict_types' in /home/runner/work/advanced-responsive-video-embedder/advanced-responsive-video-embedder/vendor/phpunit/phpunit/src/Framework/Assert/Functions.php on line 1
PHP Fatal error:  Default value for parameters with a class type hint can only be NULL in /home/runner/work/advanced-responsive-video-embedder/advanced-responsive-video-embedder/vendor/phpunit/phpunit/src/Framework/Assert/Functions.php on line [9](https://github.com/nextgenthemes/advanced-responsive-video-embedder/actions/runs/5004518879/jobs/8967195141#step:14:10)0
Error: Process completed with exit code 255.

strict_types implies it some code running that is expecting a php version that is 7.x no idea what that happens.

Because for php 7.2 I get another error and it runs in /home/runner/.composer/vendor

Run phpunit --testsuite arve,arve-pro,arve-random-video,arve-amp,arve-sticky-videos
Installing...
Running as single site... To run multisite, use -c tests/phpunit/multisite.xml
Not running ajax tests. To execute these, use --group ajax.
Not running ms-files tests. To execute these, use --group ms-files.
Not running external-http tests. To execute these, use --group external-http.
PHP Fatal error:  Uncaught Error: Call to undefined method PHPUnit\TextUI\TestRunner::doRun() in /home/runner/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:235

Stack trace:
#0 /home/runner/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php(194): PHPUnit\TextUI\Command->run(Array, true)
#1 phpvfscomposer:///home/runner/.composer/vendor/phpunit/phpunit/phpunit(97): PHPUnit\TextUI\Command::main()
#2 /home/runner/.composer/vendor/bin/phpunit(11[8](https://github.com/nextgenthemes/advanced-responsive-video-embedder/actions/runs/5004518879/jobs/8967195349#step:14:9)): include('phpvfscomposer:...')
#3 {main}
  thrown in /home/runner/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php on line 235
Fatal error: Uncaught Error: Call to undefined method PHPUnit\TextUI\TestRunner::doRun() in /home/runner/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:235
Stack trace:
#0 /home/runner/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php(1[9](https://github.com/nextgenthemes/advanced-responsive-video-embedder/actions/runs/5004518879/jobs/8967195349#step:14:10)4): PHPUnit\TextUI\Command->run(Array, true)
#1 phpvfscomposer:///home/runner/.composer/vendor/phpunit/phpunit/phpunit(97): PHPUnit\TextUI\Command::main()
#2 /home/runner/.composer/vendor/bin/phpunit([11](https://github.com/nextgenthemes/advanced-responsive-video-embedder/actions/runs/5004518879/jobs/8967195349#step:14:12)8): include('phpvfscomposer:...')
#3 {main}
  thrown in /home/runner/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php on line 235
Error: Process completed with exit code [25](https://github.com/nextgenthemes/advanced-responsive-video-embedder/actions/runs/5004518879/jobs/8967195349#step:14:26)5.

Any idea what is wrong? Again I think the readme should point to an actual maintained project that uses Githhub actions for this.

Not all the test code is part of that repo anymore and its in a private repo now but I had a monorepo strcture b4 and and the that did not change AFAIK. Here is the phpunit boot. https://github.com/nextgenthemes/advanced-responsive-video-embedder/blob/a9d19f49eb63d6d5df6c96c343db29ad77b7b859/phpunit-boot.php

jrfnl commented 1 year ago

@nextgenthemes As far as I can see your issue is not related to this repo, but to the setup-php action.

Having said that, I have a suspicion of what may be the cause of the issues. Could you add an extra step after the "Setup PHP, with composer and extension" step to gather some more information ?

Once you have done this and got a link to a workflow, please drop a link here so I can have a look.

      - name: Debug - composer global info
        run: composer global info
      - name: Debug - PHPUnit version
        run: phpunit --version
jrfnl commented 1 year ago

@nextgenthemes Just for arguments sake, I've set up a minimal scenario to test that the setup-php tools setup with phpunit-polyfills works and I cannot reproduce the issues you are seeing. Everything works as expected.

All in all, I think your problem is something else altogether and unrelated to either setup-php or the PHPUnit Polyfills.

This is the code I've used to test everything: https://github.com/jrfnl/bug-report-reproduction-scenarios/commit/7a2c211a72b7c618b5e107c218e7293eaaa2774b

This is the resulting workflow run confirming that everything works as it should: https://github.com/jrfnl/bug-report-reproduction-scenarios/actions/runs/5006929088

jrfnl commented 1 year ago

Thinking this over some more, I suspect (but haven't verified) that your problem is that you install PHPUnit twice - once via Setup PHP, once via Composer and then you load the vendor/autoload.php file from your test bootstrap.

Chances are high that that means PHPUnit will have a mismatch in versions between your local and your global composer installs and if that's the case, I'm not surprised you are seeing issues.

nextgenthemes commented 1 year ago

@jrfnl Thanks so much, the bug report test code you linked was basically exactly what I was looking for. I just wanted to make sure I am not going down a many hour long trail and error hell again for something that may be an issue others ran into. I expected that this may not be a issue with this at all, I was very desperate. Did way to many things at once as usual.

I am so glad I filed this and you responded and put in on the right track right away. You are totally right, I did "install" things twice. I forgot to exclude a /vendor folder that I use for my local testing that was never supposed to end up on Github, so that fucked everything up. Your assumption that I loaded this was right. It was actually supposed to NOT load.

if ( is_file( __DIR__ . '/vendor/autoload.php' ) ) {
    require_once __DIR__ . '/vendor/autoload.php';
}

Should probably use a better check for it. ! getenv( 'GITHUB_CI' ) or something like that. Again, thanks you very much.