phpstan / extension-installer

Composer plugin for automatic installation of PHPStan extensions.
MIT License
410 stars 27 forks source link

Allow specifying a list of extensions to ignore. #70

Closed mad-briller closed 1 year ago

mad-briller commented 1 year ago

This is useful when you don't want to auto-discover a particular phpstan extension, but still want the benefit of the extension installer for all other packages

for example when developing Drupal modules, it's common to include drupal/core-dev for testing or other purposes, however drupal/core-dev has a peer dependency on mgalman/phpstan-drupal, which the extension installer then finds and installs as you'd expect.

however, the mgalman/phpstan-drupal extension wants a full working copy of drupal, which is not available when running in a CI environment for a single module. ideally we want to ignore the installation of that extension but not at the cost of extension auto-discovery

thanks for your time

ondrejmirtes commented 1 year ago

Would be nice to add another job here https://github.com/phpstan/extension-installer/blob/1.2.x/.github/workflows/integration-tests.yml to verify that the code works :)

ondrejmirtes commented 1 year ago

And also update the README.

mad-briller commented 1 year ago

was wondering how to add a test for it tbh, do you have any advice for me? new to github actions and not sure where to begin

something like:

  1. modify the composer.json to include a known 1st party extension and ignore it
  2. run the installation
  3. ensure that the package isn't present in the GeneratedConfig

perhaps?

ondrejmirtes commented 1 year ago

Anything to reproduce the actual scenario that ignore would fix, without relying on any 3rd party repository.

1) Move the current contents of e2e/ into a subdirectory so that we can test more stuff in e2e/. 2) Add a subdirectory with an "extension" that supports extension-installer, make a rule that always reports an error, or crashes PHPStan. 3) Add another subdirectory that requires the extension from 2) as a package, and also requires phpstan/extension-installer, and contains the new ignore setting to actually exclude the extension. And runs PHPStan on a piece of code to verify the extension was not loaded. I expect the composer.json in this directory to have two entries in repositories, similar to https://github.com/phpstan/extension-installer/blob/3f3d1ba8417da188b606408dfc6722a5b420e80f/e2e/composer.json#L8-L16 - one for the extension from 2), one for extension-installer.

mad-briller commented 1 year ago

thanks for the detailed steps, that helped alot

you can see here that it was ignored: https://github.com/phpstan/extension-installer/actions/runs/4732666346/jobs/8399123646?pr=70#step:4:30

ondrejmirtes commented 1 year ago

Wow, it's great when someone listens and does everything correctly on the first try :) Thank you very much!

I'm gonna release this as 1.3.0.