WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.37k stars 4.15k forks source link

Composer autoloader misses dependencies on Windows in cli container #52291

Open ZachWatkins opened 1 year ago

ZachWatkins commented 1 year ago

Description

When I run wp-env run cli --env-cwd=wp-content/themes/wordpress-theme composer dumpautoload from Powershell on Windows 11, it builds an incomplete class list in vendor/composer/autoload_classmap.php and an exception is thrown due to a missing class when I run wp-env run cli --env-cwd=wp-content/themes/wordpress-theme ./vendor/bin/pest.

Output:

Generating optimized autoload files (authoritative)
Generated optimized autoload files (authoritative) containing 2002 classes

Test Exception:

ERROR  Class "PHPUnit\Metadata\Parser\Registry" not found
Location: /var/www/html/wp-content/themes/wordpress-theme/vendor/phpunit/phpunit/src/Util/Test.php:31   

When I run wp-env run wordpress --env-cwd=wp-content/themes/wordpress-theme composer dumpautoload from Powershell on Windows 11, the class list is complete and I am able to run wp-env run cli --env-cwd=wp-content/themes/wordpress-theme ./vendor/bin/pest with passing tests.

Output:

Generating optimized autoload files (authoritative)
Generated optimized autoload files (authoritative) containing 2109 classes

Test Success:

PASS  Tests\Feature\ExampleTest
 ✓ example                                                                                      0.56s  

PASS  Tests\Unit\ExampleTest
 ✓ example                                                                                      0.15s  

Tests:    2 passed (2 assertions)
Duration: 4.63s

My repo is here: https://github.com/ZachWatkins/wordpress-theme

Step-by-step reproduction instructions

  1. On Windows 11 (and presumably 10), open Powershell.
  2. Clone the repo: git clone https://github.com/ZachWatkins/wordpress-theme
  3. Switch to the repo's directory: cd wordpress-theme
  4. If using NVM and not using Node version 18.16.1, then switch to that Node version: nvm use
  5. Install NPM dependencies: npm install
  6. Start Docker Desktop
  7. Start the wp-env package's Docker containers: npm start
  8. Install Composer dependencies using the cli environment: npm run wp-env run cli -- --env-cwd=wp-content/themes/wordpress-theme composer install
  9. Run the tests: npm run wp-env run cli -- --env-cwd=wp-content/themes/wordpress-theme ./vendor/bin/pest

Screenshots, screen recording, code snippet

No response

Environment info

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

mburridge commented 1 year ago

Thanks for raising this issue @ZachWatkins. Could you explain why you posted this as an issue in the Gutenberg repo? Might this issue be better posted over in https://github.com/wp-cli/wp-cli?

ZachWatkins commented 1 year ago

Thanks for raising this issue @ZachWatkins. Could you explain why you posted this as an issue in the Gutenberg repo? Might this issue be better posted over in https://github.com/wp-cli/wp-cli?

I posted this issue in the Gutenberg repo because it involves the @wordpress/env NPM package's Docker containers and does not use WP-CLI during the issue reproduction steps.

mburridge commented 1 year ago

Okay, I added the appropriate label.

swissspidy commented 1 year ago

Might be a WSL bug according to https://github.com/composer/composer/issues/8808 / https://bugs.php.net/bug.php?id=80227 / https://github.com/microsoft/WSL/issues/5074

ZachWatkins commented 1 year ago

Might be a WSL bug according to composer/composer#8808 / https://bugs.php.net/bug.php?id=80227 / microsoft/WSL#5074

@swissspidy Thank you for finding those! I should mention the issue isn't blocking me at work in case that affects priorities. This is a personal project and I can avoid using the composer autoloader in the cli container. I'm glad it's a known issue, although an old one, and I'm agreeable with closing it or any other steps you all decide to take.

swissspidy commented 1 year ago

Let's keep it open for visibility, maybe one day Microsoft fixes this in WSL :-)

github-actions[bot] commented 1 year ago

Hi, This issue has gone 30 days without any activity. This means it is time for a check-in to make sure it is still relevant. If you are still experiencing this issue with the latest versions, you can help the project by responding to confirm the problem and by providing any updated reproduction steps. Thanks for helping out.