Setup PHP unit for Drupal 8/9

  • Create Drupal project with composer using recommended template:


  $ composer create-project drupal/recommended-project drupal-test
  $ cd drupal-test
  $ composer require drupal/core-dev
  
  • Export followings variable in your terminal session:


  $ export SIMPLETEST_DB='mysql://drupal_test:root@root/drupal_test'
  $ export SIMPLETEST_BASE_URL=http://127.0.0.1:8080
  $ export BROWSERTEST_OUTPUT_DIRECTORY="sites/simpletest/browser_output"
  

Run chromedriver if you are running JavaScript Functional tests


  $ chromedriver --port=4444
  $ export MINK_DRIVER_ARGS_WEBDRIVER='["chromedriver", null, "http://localhost:4444"]'
  

Run server using drush command to execute the tests:


  $ drush runserver 8080
  

Execute your test from project web directory(document root) for example:


  $ ../vendor/bin/phpunit -c core --debug modules/custom/module_name/tests/src/FunctionalJavascript/SomeTest.php
  

Comments

Popular posts from this blog

How to setup Drupal 8 Multisite on nginx webserver with different domain.

Install drush globally using composer on WSL

Drupal views create exposed filter programmatically