This is a demo repository for running PHPUnit and Behat tests in Drupal 8 projects. It contains:
- A demo module with a unit and kernel test.
- A demo Behat test.
- CircleCI integration to run the above on every pull request.
If you want to test and individul module and not a whole Drupal site, see drupal_tests.
Demo https://www.youtube.com/watch?v=Uc3vI8ztsqU
-
Run
composer install
from the repository root. -
Copy
core/phpunit.xml.dist
tocore/phpunit.xml
. -
Run unit and kernel tests in the
modules/custom
directory:
cd web
../vendor/bin/phpunit -c core --verbose --debug modules/custom
Demo https://www.youtube.com/watch?v=XoxRv8x5ZIs
Full docs at https://behat-drupal-extension.readthedocs.io/en/3.1/localinstall.html
Install Drupal as usual. Follow instructions at https://www.drupal.org/docs/8/install.
Open http://www.seleniumhq.org/download and download it to a sub-directory of your home directory.
- Download it from https://sites.google.com/a/chromium.org/chromedriver/downloads into a temporary directory.
- Place it in a directory listed by the
$PATH
variable. For example, in Ubuntu you could runsudo mv /tmp/chromedriver /usr/local/bin
.
[juampy@carboncete ~/Software]$ java -jar selenium-server-standalone-3.6.0.jar
cd /path/to/composer.json
composer require --dev drupal/drupal-extension:master-dev
Open tests/behat.yml and check that base_url
and drupal_root
are correct.
[juampy@carboncete /var/www/drupal/d8cidemo/web (master)]$ ../vendor/bin/behat --verbose -c ../tests/behat.yml
Sample job run: https://circleci.com/gh/juampynr/d8cidemo/19
The brains of the CircleCI integration are at the CircleCI configuration file, which orchestrates what should happen when something is pushed to the repository.
.circleci/config.yml
uses a container for MariaDB, another one for PhantomJS (used for
Behat tests) and a custom image for setting up the Drupal environment.
Install the CircleCI command line interface at https://circleci.com/docs/2.0/local-jobs/. Then
clone this repository and run the job with circleci build
.
Sign up with GitHub at https://circleci.com/signup/ and then allow access to your fork of this repository. Then either trigger a build manually, push a change or create a pull request to trigger the build job. Then see the results at https://circleci.com/dashboard.
- An overview of testing in Drupal 8