- Install 1. Install PHPUnit and Selenium (for FunctionalJavascript tests);
you can install PHPUnit with Composer:
Code Block language bash composer require phpunit/phpunit
NOTE: For Selenium you need to install first npm. Then you can install Selenium with these commands:
Code Block language bash npm install selenium-standalone@latest -g selenium-standalone install
When Selenium is installed run command:
Code Block language bash selenium-standalone start
- You need to apply this patch contrib-modules-issues-test-running.patch.zip (Our modules depend on many contrib modules and some of these modules have issues (which can be fixed in future))
2. Check PHPUnit configuration for testing:
- Find
...
- core/phpunit.
...
- xml (if not exist just copy
...
- phpunit.xml.
...
- dist and rename to
...
- phpunit.
...
- xml)
In this file you need to specify these settings:
...
Code Block language xml <!-- Example SIMPLETEST_BASE_URL value: http://localhost -->
...
<env name="SIMPLETEST_BASE_URL" value=""/>
...
<!-- Example SIMPLETEST_DB value: mysql://username:password@localhost/databasename#table_prefix -->
...
<env name="SIMPLETEST_DB" value=""/>
...
<!-- Example BROWSERTEST_OUTPUT_DIRECTORY value: /path/to/webroot/sites/simpletest/browser_output -->
...
<env name="BROWSERTEST_OUTPUT_DIRECTORY" value=""/
...
>
For Selenium running you need to add this line in phpunit.xml:
Code Block language xml <env name="MINK_DRIVER_ARGS_WEBDRIVER" value='["chrome", null, "http://localhost:4444/wd/hub"]'/>
3. Run tests:
Run this test (for example):
Code Block language bash sudo -u www-data -E vendor/bin/phpunit -c core --group opigno_learning_path # Or the same with debug info: sudo -u www-data -E vendor/bin/phpunit -c core --group opigno_learning_path --printer="\Drupal\Tests\Listeners\HtmlOutputPrinter
...