There is already a docs page about this:
https://www.drupal.org/docs/testing/phpunit-in-drupal/running-phpunit-tests
I've tried to follow that, including creating a browser_output
directory and setting up the configuration file (phpunit.xml
).
But #2 in the instructions is a stumbling block. It says:
Use a development snapshot (for example, 8.8.x-dev) instead of a tagged release for your development site.
Fine, but it does not tell you how to to this.
So far I've tried the following two commands:
composer create-project 'drupal/recommended-project:8.9.x' web
composer create-project 'drupal/recommended-project:8.9.x' --dev web
Both commands downloads the development version of the core and installs the project – but there is no vendor/bin/phpunit
.
I am able to install PHPUnit in a separate step, i.e.:
composer require phpunit/phpunit
However, this installs 9.2.5, which I suspect is too bleeding edge for Drupal 8.9, as every attempt to run a test produces:
PHP Warning: Class 'PHPUnit\Framework\MockObject\Matcher\InvokedRecorder' not found in /var/www/web/core/tests/bootstrap.php on line 197
PHP Warning: Class 'Drupal\TestTools\PhpUnitCompatibility\PhpUnit9\HtmlOutputPrinter' not found in /var/www/ca8.roztr.org/web/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinter.php on line 15
PHPUnit 9.2.5 by Sebastian Bergmann and contributors.
Could not use "\Drupal\Tests\Listeners\HtmlOutputPrinter" as printer: class does not exist
Googling these error messages seems to indicate that there is a version mismatch (but I may be wrong about that).
So the question is: How to install Drupal 8 with PHPUnit, in order to run PHPUnit tests afterwards. I seem to need more detailed instructions than those that exists on the linked docs-page.
Environment: Ubuntu 20.04 LTS (i.e. PHP 7.4).
Comments
Discuss Running PHPUnit tests
I agree, it would be great to have the options be more detailed, like the minimum set of required commands, when using
git
orcomposer
, and which one is the recommended method. They do give you different file structures, for example.Perhaps a better place to have the discussion would be under Discuss Running PHPUnit tests?
Good idea
I've posted a note about my experiences under https://www.drupal.org/node/2116263/discuss.
- gisle
Great, thanks!
Great, thanks!
I am facing same issue. What
I am facing same issue. What is the solution for this?
Discuss Running PHPUnit tests
You probably have a better chance of getting an answer asking it on the discussion page:
https://www.drupal.org/node/2116263/discuss