Answers.Body: <p>Ok here are the steps!</p>
  <p>I'm on a Mac/MAMP and I use PhpStorm</p>
  <p><strong>A. Get Drupal</strong></p>
  <pre><code>composer create-project drupal/recommended-project:8.9.13 d8civicrm.local
  cd d8civicrm.local
  
  composer config extra.enable-patching true
  composer config minimum-stability dev
  </code></pre>
  <p><strong>B. Get CiviCRM</strong></p>
  <pre><code>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
  </code></pre>
  <p><strong>C. Install Drupal</strong></p>
  <p>Browser to your new website -&gt; in my case: <a href="http://d8civicrm.local" rel="nofollow noreferrer">http://d8civicrm.local</a>
  and follow the install step in the UI.</p>
  <p><strong>D. Make it writeable</strong></p>
  <pre><code>chmod -R +w d8civicrm.local
  </code></pre>
  <p>we need to write e.g. the <code>civicrm.settings.php</code> file next!</p>
  <p><strong>E. Install CiviCRM</strong></p>
  <p>Go to the UI -&gt; Extend -&gt; or use drush!</p>
  <p><strong>F. Patch alert!</strong></p>
  <p>No longer needed!</p>
  <p><strong>G. PHPUnit configuration</strong></p>
  <p>copy this file: <a href="https://gist.github.com/mglaman/efcdb804dcced6ddc856e9e0050aad1e" rel="nofollow noreferrer">https://gist.github.com/mglaman/efcdb804dcced6ddc856e9e0050aad1e</a>
  -&gt; into /Applications/MAMP/htdocs/d8civicrm.local (i.e. where your composer.json is) and make updates specifically add in your <code>BASE_URL</code> and your <code>DB</code> location and credentials:</p>
  <pre><code>19c19
  &lt;     &lt;env name=&quot;SIMPLETEST_BASE_URL&quot; value=&quot;http://d8civicrm.local&quot;/&gt;
  ---
  &gt;     &lt;env name=&quot;SIMPLETEST_BASE_URL&quot; value=&quot;&quot;/&gt;
  21c21
  &lt;     &lt;env name=&quot;SIMPLETEST_DB&quot; value=&quot;mysql://myadminuser:db^88*@localhost:3306/d8civicrm_local&quot;/&gt;
  ---
  &gt;     &lt;env name=&quot;SIMPLETEST_DB&quot; value=&quot;&quot;/&gt;
  </code></pre>
  <p>Note: when testing CiviCRM Extensions -&gt; add this line as well - as per docs:
  docs -&gt; <a href="https://docs.civicrm.org/dev/en/latest/testing/mink/" rel="nofollow noreferrer">https://docs.civicrm.org/dev/en/latest/testing/mink/</a></p>
  <pre><code>&lt;env name=&quot;DEV_EXTENSION_DIR&quot; value=&quot;/Applications/MAMP/htdocs/d9civicrm.local/web/sites/default/files/civicrm/ext/&quot;/&gt;
  </code></pre>
  <p><strong>H. Install webform module</strong></p>
  <p>composer require 'drupal/webform:^6.0'</p>
  <p><strong>I. Install webform_civicrm module</strong></p>
  <p>-&gt; (at this points the tests have not been released yet so you'll need to clone the webform civicrm github repo):</p>
  <pre><code>git clone https://github.com/colemanw/webform_civicrm.git --branch 8.x-5.x
  </code></pre>
  <p><strong>J. Get the Drupal Dev tools</strong></p>
  <p>We started with <code>drupal-recommended</code> - now let's get the dev tools:</p>
  <pre><code>composer config minimum-stability dev
  composer require drupal/core-dev-pinned:^8.9 --no-suggest
  </code></pre>
  <p>Note: reproducing this just now - I ended up having to <code>rm composer.lock</code> and <code>rm -r vendor</code> as it was spitting out a symfony conflict. Ah looks like in the <code>.github/workflows/main.yml</code> file we install the drupal dev tools before we install CiviCRM</p>
  <p><strong>K. Configure PHPStorm</strong></p>
  <p>PHPStorm -&gt; Preferences -&gt; Language &amp; Frameworks -&gt; PHP -&gt; Test Frameworks.</p>
  <p><a href="https://i.sstatic.net/dEV5C.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/dEV5C.png" alt="enter image description here" /></a></p>
  <p>If running into autoloading issues - things to try:
  add the entire path to phpunit -&gt; /Applications/MAMP/htdocs/d9civicrm.local/vendor/phpunit/phpunit as a PHP include path in Languages and Frameworks in the PhpStorm settings - hit Apply -&gt; then check the Test Frameworks page again.</p>
  <p><a href="https://i.sstatic.net/zUczV.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/zUczV.png" alt="enter image description here" /></a></p>
  <p><strong>L. Install Chromedriver</strong></p>
  <p><a href="https://chromedriver.chromium.org/" rel="nofollow noreferrer">https://chromedriver.chromium.org/</a></p>
  <p>and start it</p>
  <pre><code>/usr/local/bin/chromedriver
  To check that it's running:
  karins-MBP:bin sysadmin$ ps -ax |grep chromedriver
  62821 ttys004 0:00.18 chromedriver
  </code></pre>
  <p><strong>M. Run a test!</strong></p>
  <p>Before you can run a test -&gt; you need to drop all tables and triggers from your database or you'll hit this error (below). Of course make a backup if you have any configs you'd like to keep.</p>
  <pre><code>1) Drupal\Tests\webform_civicrm\FunctionalJavascript\ContributionDummyTest::testOnePageDonation
  RuntimeException: The provided database connection in SIMPLETEST_DB contains CiviCRM tables, use a different database.
  </code></pre>
  <p><a href="https://i.sstatic.net/rpTxo.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/rpTxo.jpg" alt="enter image description here" /></a></p>
  <p>PS - Note to self: if you run into:
  <code>Error : Call to undefined method CRM_Utils_System_UnitTests::parseUrl()</code></p>
  <p>Go into -&gt; Run/Debug Configurations and hit Environment Variables and SWITCH OFF -&gt; Include system environment variables (as one may have included variables specific to CiviCRM Unit Testing)</p>
  <p>I'm still working on getting xdebug to work with phpunit test - in the mean time -&gt; to debug variables within your unit test -&gt;</p>
  <pre><code>$result_debug = var_export($contact_result);    
  </code></pre>
  <p>or</p>
  <pre><code>throw new \Exception(var_export($api_result, TRUE));
  
  Also handy for local screenshots -&gt; e.g.
      $this-&gt;htmlOutputDirectory = '/Applications/MAMP/htdocs/d9civicrm.local/web/sites/default/files/simpletest/';
      $this-&gt;createScreenshot($this-&gt;htmlOutputDirectory . 'KG.png');
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-12T03:55:11.947Z
Answers.Text: great documentation
Answers.UserDisplayName: petednz - fuzion
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-11T19:51:33.690Z
Answers.LastActivityDate: 2022-06-21T17:19:15.910Z
Answers.LastEditDate: 2022-06-21T17:19:15.910Z
Answers.UserDisplayName: KarinG - Semper IT
Body: <p>D9 Webform CiviCRM now has automated functional javascript testing! How can I run these tests on my local?</p>
  
Tags: <webform-civicrm><drupal-8><drupal-9>
Title: How can I run the Drupal 9 Webform CiviCRM unit tests on my local?
ThreadText: # How can I run the Drupal 9 Webform CiviCRM unit tests on my local?
  
  (Asked by: username_0 on 2020-11-11)
  
  D9 Webform CiviCRM now has automated functional javascript testing! How can I run these tests on my local?
  
  **Tags:** webform-civicrm, drupal-8, drupal-9
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2020-11-11. Score: 7 | Accepted answer
  
  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
  
  composer config extra.enable-patching true
  composer config minimum-stability dev
  
  ```
  
  **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=""/>
  
  ```
  
  Note: when testing CiviCRM Extensions -> add this line as well - as per docs:
  docs -> <https://docs.civicrm.org/dev/en/latest/testing/mink/>
  
  ```
  <env name="DEV_EXTENSION_DIR" value="/Applications/MAMP/htdocs/d9civicrm.local/web/sites/default/files/civicrm/ext/"/>
  
  ```
  
  **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](https://i.sstatic.net/dEV5C.png)](https://i.sstatic.net/dEV5C.png)
  
  If running into autoloading issues - things to try:
  add the entire path to phpunit -> /Applications/MAMP/htdocs/d9civicrm.local/vendor/phpunit/phpunit as a PHP include path in Languages and Frameworks in the PhpStorm settings - hit Apply -> then check the Test Frameworks page again.
  
  [![enter image description here](https://i.sstatic.net/zUczV.png)](https://i.sstatic.net/zUczV.png)
  
  **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!**
  
  Before you can run a test -> you need to drop all tables and triggers from your database or you'll hit this error (below). Of course make a backup if you have any configs you'd like to keep.
  
  ```
  1) Drupal\Tests\webform_civicrm\FunctionalJavascript\ContributionDummyTest::testOnePageDonation
  RuntimeException: The provided database connection in SIMPLETEST_DB contains CiviCRM tables, use a different database.
  
  ```
  
  [![enter image description here](https://i.sstatic.net/rpTxo.jpg)](https://i.sstatic.net/rpTxo.jpg)
  
  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)
  
  I'm still working on getting xdebug to work with phpunit test - in the mean time -> to debug variables within your unit test ->
  
  ```
  $result_debug = var_export($contact_result);    
  
  ```
  
  or
  
  ```
  throw new \Exception(var_export($api_result, TRUE));
  
  Also handy for local screenshots -> e.g.
      $this->htmlOutputDirectory = '/Applications/MAMP/htdocs/d9civicrm.local/web/sites/default/files/simpletest/';
      $this->createScreenshot($this->htmlOutputDirectory . 'KG.png');
  
  ```
  
  > **Comments:**
  > **username_1**: great documentation  
  
  ---
  
  