Use fallback for $_composer_autoload_path
#760
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes a bug I discovered where the
lucatume\WPBrowser\Utils\Composer::autoloadPath()
method will throw aTypeError
if the$_composer_autoload_path
global is undefined. The previous code passed the global torealpath()
without checking if it actually exist.Apparently
$_composer_autoload_path
can be undefined in various binary contexts — I stumbled across this when trying to use PhpStorm's test runner on test classes & methods that use#[RunTestsInSeparateProcesses]
and theIsolationSupport
extension.Therefore, Composer recommends having a fallback. (Moreover, without one, the method signature may be incorrect and usages like the
vendorDir()
method will fail if they expect a string.)I created a fallback condition that first looks for
vendor
in the same directory ascodeception.yml
. If that directory is not found (perhaps the parent project has customized Composer'svendor-dir
), it guesses what the autoload path ought to be by walking up directories to where wp-browser should be installed.I have not changed the original behavior of always returning a string, even if
realpath()
complains that the file does not exist.Unit tests for various scenarios are included. Obviously they have to manipulate the global, so I've used
@backupGlobals enabled
, which appears to be sufficient.