D8 Webform CiviCRM now has automated unit testing! How can I run these unit tests on my local?
Ok here are the steps!
I'm on a Mac/MAMP and I use PhpStorm
A. Get Drupal
composer create-project drupal/recommended-project:8.9.8 d8civicrm.local cd d8civicrm.local
B. Get CiviCRM
composer require civicrm/civicrm-core:5.31.0 civicrm/civicrm-packages:5.31.0 civicrm/civicrm-drupal-8:5.31.0 civicrm/civicrm-asset-plugin:~1.1
C. Install Drupal
Browser to your new website -> in my case: https://d8civicrm.local and follow the install step in the UI.
D. Make it writeable
chmod -R +w d8civicrm.local
we need to write e.g. the
civicrm.settings.php file next!
E. Install CiviCRM
Go to the UI -> Extend -> or use drush!
F. Patch alert!
At this point CiviCRM 5.31 -> you will need this patch - it has been merged and should be in CiviCRM 5.32 https://github.com/civicrm/civicrm-core/commit/eb401bd4093c2b63d79eaf911776a65f47f2ecfb
G. PHPUnit configuration
copy this file: https://gist.github.com/mglaman/efcdb804dcced6ddc856e9e0050aad1e
-> into /Applications/MAMP/htdocs/d8civicrm.local (i.e. where your composer.json is) and make updates specifically add in your
BASE_URL and your
DB location and credentials:
19c19 < <env name="SIMPLETEST_BASE_URL" value="http://d8civicrm.local"/> --- > <env name="SIMPLETEST_BASE_URL" value=""/> 21c21 < <env name="SIMPLETEST_DB" value="mysql://myadminuser:db^88*@localhost:3306/d8civicrm_local"/> --- > <env name="SIMPLETEST_DB" value=""/>
H. Install webform module
composer require 'drupal/webform:^5.22'
I. Install webform_civicrm module
-> (at this points the tests have not been released yet so you'll need to clone the webform civicrm github repo):
git clone https://github.com/colemanw/webform_civicrm.git --branch 8.x-5.x
J. Get the Drupal Dev tools
We started with
drupal-recommended - now let's get the dev tools:
composer require drupal/core-dev-pinned --dev
K. Configure PHPStorm
PHPStorm -> Preferences -> Language & Frameworks -> PHP -> Test Frameworks:
L. Install Chromedriver
and start it
/usr/local/bin/chromedriver To check that it's running: karins-MBP:bin sysadmin$ ps -ax |grep chromedriver 62821 ttys004 0:00.18 chromedriver
M. Run a test!
PS - Note to self: if you run into:
Error : Call to undefined method CRM_Utils_System_UnitTests::parseUrl()
Go into -> Run/Debug Configurations and hit Environment Variables and SWITCH OFF -> Include system environment variables (as one may have included variables specific to CiviCRM Unit Testing)