symfonyphpunitshopwareshopware6

How Do I Test Shopware 6 plugin using PHPUnit


How do I carryout PHPUnit tests on a Shopware plugin.

Do I have to install PHPunit first within the plugin?

When I run ./vendor/bin/phpunit --configuration="custom/plugins/PluginToTestPHPUnit" I get the message "

Fatal error: Uncaught Error: Class "PHPUnit\TextUI\Application" not found in /var/www/html/vendor/phpunit/phpunit/phpunit:104
Stack trace:
#0 /var/www/html/vendor/bin/phpunit(120): include()
#1 {main}
  thrown in /var/www/html/vendor/phpunit/phpunit/phpunit on line 104

on the command line.

I am working with Shopware version 6.5.7.3


Solution

  • It depends on what test do you want to run. If only unit test, then install PHPUnit as a dev dependency directly in the plugin. If you want to perform integration or application tests, then install it in the main project. https://developer.shopware.com/docs/guides/plugins/plugins/testing/php-unit.html here docs on testing. Create a new plugin and checkout the TestBootstrap.php and phpunit.xml files.