1

D8 Webform CiviCRM now has automated unit testing! How can I run these unit tests on my local?

5

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.13 d8civicrm.local
cd d8civicrm.local

B. Get CiviCRM

composer require civicrm/civicrm-core:5.35.0 civicrm/civicrm-packages:5.35.0 civicrm/civicrm-drupal-8:5.35.0 civicrm/civicrm-asset-plugin:~1.1

C. Install Drupal

Browser to your new website -> in my case: http://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!

No longer needed!

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:^6.0'

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 config minimum-stability dev composer require drupal/core-dev-pinned:^8.9 --no-suggest

Note: reproducing this just now - I ended up having to rm composer.lock and rm -r vendor as it was spitting out a symfony conflict. Ah looks like in the .github/workflows/main.yml file we install the drupal dev tools before we install CiviCRM

K. Configure PHPStorm

PHPStorm -> Preferences -> Language & Frameworks -> PHP -> Test Frameworks.

enter image description here

If running into autoloading issues - things to try: composer update add vendor/phpunit/phpunit as a PHP include path in Languages and Frameworks in the PhpStorm settings - Apply

L. Install Chromedriver

https://chromedriver.chromium.org/

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!

enter image description here

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)

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.