Problem/Motivation
PHPStand command failed while trying to check for deprecated drupal 8 code.
Steps to reproduce
In our semi composer set up, we have modules/custom. When trying to check against them, they all throw this error.
Problem is that following is TRUE and not a class.
/** @var \Composer\Autoload\ClassLoader $loader */
$loader = require __DIR__ . '/../../autoload.php';
Running drupal-check gives me the same issue:
wodby@php.container:/var/www/html/drupal/vendor/bin $ ./drupal-check -ad ../../modules/custom/ --drupal-root=/var/www/html/drupal
Error thrown in /var/www/html/drupal/core/tests/bootstrap.php on line 141 while loading bootstrap file /var/www/html/drupal/vendor/mglaman/phpstan-drupal/drupal-autoloader.php: Call to a member function add() on bool
Am I the only one facing this?
Comments
Comment #2
Gábor HojtsyAre you running upgrade status with drush or on the UI? Does this only happen for custom modules and not contributed projects?
Comment #3
ichionid CreditAttribution: ichionid commentedComment #4
ichionid CreditAttribution: ichionid commentedOnly for custom modules in the UI. Happens also in the console. Contrib modules reside in my composer.json file.
Comment #5
Gábor HojtsyHm, why does it use
core/tests/bootstrap.php
? Did you add the phpunit test dependencies as per the project page?Comment #6
ichionid CreditAttribution: ichionid commentedDone nothing special rather than running the modules. There are phpunit dependencies in code. But could it be that it is only working for composer based installations? I noticed, trying to use composerize, that it removed the autoload.php file fx. Makes me wonder if the standard non-composer is not supported.
Comment #7
Gábor HojtsyThe project page explains how to set up a composer based setup for testing if your site is not using composer. Did you follow that? I wonder how did you install the module without composer if you are not using composer?
Comment #8
ichionid CreditAttribution: ichionid commentedMaybe I am not getting through. We're using a composer set up. We're however not having the same structure as https://github.com/drupal-composer/drupal-project
We have our modules under modules/custom and not web/modules/custom fx
I did follow the instruction for moving my modules/custom to web/modules/custom but it does not make any difference.
Comment #9
Gábor HojtsyHm, that IMHO should not change how the module finds things. Your custom modules could be in
web/modules/foo/bar/modules/modules/foo
or whatnot. As long as Drupal understands that they are there (ie. they were installed from there).Comment #10
ichionid CreditAttribution: ichionid commentedEnded up using a dockerized version of drupal-check. This is very weird.
Comment #11
Gábor HojtsyHm, does that work?
Comment #12
ichionid CreditAttribution: ichionid commentedYes my workaround is to use the dockerized version and move all my custom modules to a fresh composer project just to run the checks there. Workaround to this madness :p
Comment #13
mglamanDue to some fancy PHPUnit bridge work in Drupal, we need to call the PHPUnit bootstrap script to fix some namespaces. I have tried avoiding this but cannot seem to get it to work just right.
It looks likeActually, returning TRUE is the behavior of include_once or require_once. So I am not sure why it would return TRUE over anything else.require
is returning true because the autoloader in/web
or/docroot
has already been loaded:OR! Are you not on a Composer based build and this is a general problem since the Drupal "fake" autoloader is the main one?
Here is where phpstan-drupal includes the bootstrap.php to work around PHPUnit bridge problems
https://github.com/mglaman/phpstan-drupal/blob/main/src/Drupal/DrupalAut...
Actually, did I screw up by calling require_once above? Which broke later inclusions.
Comment #14
mglamanI made this PR to clean up part of the loading to see if require_once is needed or not, because maybe that's the problem: https://github.com/mglaman/phpstan-drupal/pull/203
@ichionid can you hack your local files to replace require_once with require in the phpstan-drupal DrupaAutoloader to see if that makes a difference?
Comment #15
ichionid CreditAttribution: ichionid commented@mglaman thanks! Will follow up shortly next week :)
Comment #16
mglamanCool, thanks @ichionid! I'm pushing to needs more info for now, to make the queue easier to manage.
Comment #17
mglamanI merged the PR anyways since tests were green. A new release will be out with the fix. Let me know if its still a problem.
Comment #18
ichionid CreditAttribution: ichionid commentedFirst thing tomorrow. Thanks! :)
Comment #19
Gábor Hojtsy@ichionid had other priorities I think :) It looks like we can close this though as the underlying issue has been fixed.