Package tests do not load command's composer dependencies
aaemnnosttv opened this issue · 4 comments
My package uses Composer for autoloading and works just fine when installing via wp package install
.
However trying to get it to run with behat has been difficult since the installation is different in that only the package's command.php
is loaded by the test wp-cli config. This causes behat to fail because my command's classes are not being loaded.
In the end I got it to work by pointing $WP_CLI_BIN_DIR
to vendor/wp-cli/wp-cli/bin/
in my package.
Perhaps one way to solve this would be to have wp-cli install the package as a package but to reference the local repository rather than the wp-cli package-index doing something like this.
That or maybe we could concoct a wp-cli/package-tests
dependency that packages could require-dev to pull in everything needed for these tests locally (wp-cli, behat, utils, etc), rather than relying on the install script - or at least simplify it.
Thoughts?
However trying to get it to run with behat has been difficult since the installation is different in that only the package's command.php is loaded by the test wp-cli config. This causes behat to fail because my command's classes are not being loaded.
What if we implemented the psr-4
autoloader? Or, could you require vendor/autoload.php
from command.php
if it exists?
That or maybe we could concoct a wp-cli/package-tests dependency that packages could require-dev to pull in everything needed for these tests locally (wp-cli, behat, utils, etc), rather than relying on the install script - or at least simplify it.
There's some discussion of this in #13
Behat has a boostrap
configuration that lets you add a folder for which all *.php
files will be loaded before a test is run. Haven't tested this, but simply adding ./vendor/
as the bootstrap folder might work, as it would only contain the autoload.php
file. For more control, the package could include a bootstrap folder for Behat to load.
This is fixed by #63
Hi,
I'm trying to include unit tests in my package but I'm struggling with this issue and can't get it working (Error: Callable "Vendor\\Name\\Command" does not exist, and cannot be registered as 'wp my_command'
). I'm using a custom local path as repository.
Could you provide a PSR4 autoloading working example?