Skip to content

Instantly share code, notes, and snippets.

@davidjguru
Last active August 28, 2024 05:22
Show Gist options
  • Save davidjguru/dd645fedef51008fe6b7f8753880b09f to your computer and use it in GitHub Desktop.
Save davidjguru/dd645fedef51008fe6b7f8753880b09f to your computer and use it in GitHub Desktop.

Revisions

  1. davidjguru revised this gist Nov 10, 2021. 2 changed files with 36 additions and 0 deletions.
    19 changes: 19 additions & 0 deletions drupal_8_9_configure_phpunit_for_testing.md
    Original file line number Diff line number Diff line change
    @@ -36,6 +36,12 @@ $ php -v

    PHP 7.4.20 (cli) (built: Jun 4 2021 23:17:27) ( NTS )
    ```
    --------------------------------

    ```bash
    $ composer show drupal/core |grep versions
    versions : * 8.9.19
    ```

    # 2- Resolve dependencies

    @@ -67,16 +73,23 @@ Using version ^1.3 for behat/mink-goutte-driver
    Using version ^1.5 for behat/mink-selenium2-driver
    Using version ^2.0 for phpspec/prophecy-phpunit
    ```

    But for Drupal 8 I'm installing:

    ```bash
    $ ddev composer require phpunit/phpunit:^7 --with-dependencies
    ```

    ```bash
    $ composer require phpunit/phpunit:^7
    $ composer require symfony/phpunit-bridge:^3.4.3
    $ composer require behat/behat:^3.4
    $ composer require behat/mink:^1.8
    $ composer require behat/mink-goutte-driver:^1.2
    $ composer require behat/mink-selenium2-driver:^1.5.0
    ```


    # 3- Copy and rename the phpunit.xml file

    Locate the file at `/project/web/core/phpunit.xml.dist`. It’s necessary to make a copy of the file and rename it as phpunit.xml
    @@ -136,6 +149,12 @@ newdeploy$ ddevdestroy #Stop the DDEV deploy, disabling the containers and delet
    $ # Returns to the previous folder.
    ```

    Or you can use:
    ```bash
    $ d9ddev && d9phpunit
    $ d8ddev && d8phpunit
    ```

    This Require using DDEV for local deploys, you can read more about this tool here:
    * [DDEV-Local Documentation](https://ddev.readthedocs.io/en/stable/)
    * [How To Develop a Drupal 9 Website on Your Local Machine Using Docker and DDEV](https://www.digitalocean.com/community/tutorials/how-to-develop-a-drupal-9-website-on-your-local-machine-using-docker-and-ddev)
    17 changes: 17 additions & 0 deletions script_bash_d9ddev → script_bash_d8_d9_ddev
    Original file line number Diff line number Diff line change
    @@ -35,6 +35,23 @@ d9phpunit () {
    ddev exec ./vendor/bin/phpunit -c web/core /var/www/html/web/modules/contrib/admin_toolbar
    }

    ## Same but for Drupal 8.
    d8phpunit () {
    varkeyname=basename $(pwd)
    string_url="<env name='BROWSERTEST_OUTPUT_BASE_URL' value='http://${varkeyname}.ddev.site/'/>"
    ddev composer require --dev phpunit/phpunit:^7 symfony/phpunit-bridge:^3.4.3 \
    behat/mink-goutte-driver:^1.2 behat/behat:^3.4 behat/mink:^1.8 \
    behat/mink-selenium2-driver:^1.5.0 --with-all-dependencies
    cd web/core
    cp phpunit.xml.dist phpunit.xml
    sed -i 's+<env name="SIMPLETEST_BASE_URL" value=""/>+<env name="SIMPLETEST_BASE_URL" value="http://localhost"/>+g' phpunit.xml
    sed -i 's+<env name="SIMPLETEST_DB" value=""/>+<env name="SIMPLETEST_DB" value="mysql://db:db@db/db"/>+g' phpunit.xml
    sed -i 's+<env name="BROWSERTEST_OUTPUT_DIRECTORY" value=""/>+<env name="BROWSERTEST_OUTPUT_DIRECTORY" value="/var/www/html/web/sites/default/simpletest/browser_output/"/>+g' phpunit.xml
    sed -i 's+<env name="BROWSERTEST_OUTPUT_BASE_URL" value=""/>+'"$string_url"'+g' phpunit.xml
    cd ../..
    ddev exec ./vendor/bin/phpunit -c web/core /var/www/html/web/modules/contrib/admin_toolbar
    }

    ## Destroy a DDEV local deploy by name using in project folder.
    ddevdestroy () {
    varkeyname=basename $(pwd)
  2. davidjguru revised this gist Nov 3, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion drupal_8_9_configure_phpunit_for_testing.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # Drupal 8 || 9 - Configure your PHPUnit environment for functional testing
    # Drupal 8 || 9 - Configure your environment for functional testing with PHPUnit

    If you need an extended and specific version of this topic, read this article:
    *[Functional testing for Browser in Drupal 8-9 using PHPUnit](https://www.therussianlullaby.com/blog/functional-testing-for-browser-in-drupal-using-phpunit/)
  3. davidjguru renamed this gist Nov 3, 2021. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. davidjguru renamed this gist Nov 3, 2021. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. davidjguru revised this gist Nov 3, 2021. 2 changed files with 83 additions and 6 deletions.
    46 changes: 46 additions & 0 deletions .bash_d9ddev
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    ## Creating Drupal projects by using DDEV.
    d9ddev () {
    if [ -z "$1" ]
    then
    check=$(shuf -n1 /usr/share/dict/words)
    shortened=${check::-2}
    varkeyname=${shortened,,}
    else
    varkeyname=$1
    fi
    mkdir $varkeyname && cd $varkeyname
    ddev config --project-type=drupal9 --docroot=web --create-docroot
    yes | ddev composer create "drupal/recommended-project:^9"
    ddev composer require drush/drush drupal/admin_toolbar drupal/devel
    ddev exec drush si --site-name=$varkeyname --account-name=admin --account-pass=admin -y
    ddev drush en -y admin_toolbar admin_toolbar_tools admin_toolbar_search admin_toolbar_links_access_filter devel
    ddev drush cr
    ddev start && ddev launch
    }

    ## Prepares a Drupal 9 installation for testing with PHPUnit executing from project folder.
    d9phpunit () {
    varkeyname=basename $(pwd)
    string_url="<env name='BROWSERTEST_OUTPUT_BASE_URL' value='http://${varkeyname}.ddev.site/'/>"
    ddev composer require --dev phpunit/phpunit symfony/phpunit-bridge \
    behat/mink-goutte-driver behat/mink-selenium2-driver \
    phpspec/prophecy-phpunit --with-all-dependencies
    cd web/core
    cp phpunit.xml.dist phpunit.xml
    sed -i 's+<env name="SIMPLETEST_BASE_URL" value=""/>+<env name="SIMPLETEST_BASE_URL" value="http://localhost"/>+g' phpunit.xml
    sed -i 's+<env name="SIMPLETEST_DB" value=""/>+<env name="SIMPLETEST_DB" value="mysql://db:db@db/db"/>+g' phpunit.xml
    sed -i 's+<env name="BROWSERTEST_OUTPUT_DIRECTORY" value=""/>+<env name="BROWSERTEST_OUTPUT_DIRECTORY" value="/var/www/html/web/sites/default/simpletest/browser_output/"/>+g' phpunit.xml
    sed -i 's+<env name="BROWSERTEST_OUTPUT_BASE_URL" value=""/>+'"$string_url"'+g' phpunit.xml
    cd ../..
    ddev exec ./vendor/bin/phpunit -c web/core /var/www/html/web/modules/contrib/admin_toolbar
    }

    ## Destroy a DDEV local deploy by name using in project folder.
    ddevdestroy () {
    varkeyname=basename $(pwd)
    ddev stop
    yes |ddev delete -O
    cd ..
    rm -rf $varkeyname
    }

    43 changes: 37 additions & 6 deletions drupal_8_9_configure_phpunit_for_testing.md
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,8 @@
    # Drupal 8 || 9 - Configure your PHPUnit environment for functional testing

    If you need an extended and specific version of this topic, read this article:
    *[Functional testing for Browser in Drupal 8-9 using PHPUnit](https://www.therussianlullaby.com/blog/functional-testing-for-browser-in-drupal-using-phpunit/)

    **Author**
    ----------------
    * David Rodríguez, [@davidjguru](https://twitter.com/davidjguru).
    @@ -15,13 +18,13 @@

    **Acknowledgments**
    -----------------------
    This snippet was composed from my current position as Senior Drupal Developer at [Digitalist Sweden](https://www.digitalist.se/english), one of the biggest companies oriented to Open Source in Europe and specifically focused in Drupal.
    This gist was composed from my current position as Senior Drupal Developer at [Digitalist Sweden](https://www.digitalist.se/english), one of the biggest companies oriented to Open Source in Europe and specifically focused in Drupal.

    # 1- Know your versions
    The first step is to know what versions are you using in your Drupal installation. Drupal changes PHPUnit required versions in Drupal 8, Drupal 9 and the PHP installed version.
    For instance, for Drupal 8 deploys you can use PHPUnit 7.x, (7.5.20 in my last test). For Drupal 9 you can use PHPUnit 8.x but if your PHP version is > 7.3 you can use PHPUnit 9.x. So first, get info about Drupal and PHP.
    The first step is to know what versions are you using in your Drupal installation. Drupal changes PHPUnit required versions in Drupal 8, Drupal 9 and the PHP installed version.
    For instance, for Drupal 8 deploys you can use PHPUnit 7.x, (7.5.20 in my last test). For Drupal 9 you can use PHPUnit 8.x but if your PHP version is > 7.3 you can use PHPUnit 9.x. So first, get info about Drupal and PHP.

    [See the Issue: Update to PHPUnit 9](https://www.drupal.org/node/3176567)
    [See the Issue: Update to PHPUnit 9](https://www.drupal.org/node/3176567)

    ```bash
    $ composer show drupal/core |grep versions
    @@ -36,7 +39,7 @@ PHP 7.4.20 (cli) (built: Jun 4 2021 23:17:27) ( NTS )

    # 2- Resolve dependencies

    For my Drupal 9 deploym, I can request something like:
    For my Drupal 9 deploy, I can request something like:

    ```bash
    $ composer require --dev phpunit/phpunit --with-all-dependencies
    @@ -64,6 +67,15 @@ Using version ^1.3 for behat/mink-goutte-driver
    Using version ^1.5 for behat/mink-selenium2-driver
    Using version ^2.0 for phpspec/prophecy-phpunit
    ```
    But for Drupal 8 I'm installing:

    ```bash
    $ composer require phpunit/phpunit:^7
    $ composer require symfony/phpunit-bridge:^3.4.3
    $ composer require behat/behat:^3.4
    $ composer require behat/mink:^1.8
    $ composer require behat/mink-goutte-driver:^1.2
    ```

    # 3- Copy and rename the phpunit.xml file

    @@ -92,7 +104,7 @@ Then, edit the `phpunit.xml` file and set new values in `<php>` section of the f
    ```bash
    $ ddev ssh
    davidjguru@container-web:/var/www/html$ cd web/
    davidjguru@container-web:/var/www/html/web$ ../vendor/bin/phpunit -c modules/contrib/admin_toolbar
    davidjguru@container-web:/var/www/html/web$ ../vendor/bin/phpunit -c core modules/contrib/admin_toolbar
    ```
    Returning:

    @@ -110,4 +122,23 @@ Returning:

    So, everything is going well! ready to run your own test! **Happy Hacking!**

    # 6- Go fast (extra)

    I have some basic scripts with all of these steps, ready-to-go creating new Drupal 9 local deploys using DDEV, preparing the Drupal 9 deploy for PHPUnit (and launching an initial testing in a contrib existing module) and finally stopping containers, disabling the DDEV deploy and deleting the project folder.

    See the next bash script, download, add in your ~/.bashrc file and use the functions.
    Example:

    ```bash
    $ d9ddev # Create a new D9 deploy with a random naming.
    newdeploy$ d9phpunit # Within the D9 deploy prepares PHPUnit and launch initial testing.
    newdeploy$ ddevdestroy #Stop the DDEV deploy, disabling the containers and deleting content.
    $ # Returns to the previous folder.
    ```

    This Require using DDEV for local deploys, you can read more about this tool here:
    * [DDEV-Local Documentation](https://ddev.readthedocs.io/en/stable/)
    * [How To Develop a Drupal 9 Website on Your Local Machine Using Docker and DDEV](https://www.digitalocean.com/community/tutorials/how-to-develop-a-drupal-9-website-on-your-local-machine-using-docker-and-ddev)
    * [Creating development environments for Drupal with DDEV](https://www.therussianlullaby.com/blog/creating-development-environments-for-drupal-with-ddev/)
    * [Books/ Local Web development with DDEV](https://www.therussianlullaby.com/blog/books-local-web-development-with-ddev-explained/)
    * [Tooling: Docker Docker-Compose DDEV - Cheatsheet](https://davidjguru.github.io/blog/tooling-docker-docker-compose-ddev-cheatsheet)
  6. davidjguru revised this gist Nov 3, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion drupal_8_9_configure_phpunit_for_testing.md
    Original file line number Diff line number Diff line change
    @@ -62,7 +62,7 @@ Using version ^9.5 for phpunit/phpunit
    Using version ^5.3 for symfony/phpunit-bridge
    Using version ^1.3 for behat/mink-goutte-driver
    Using version ^1.5 for behat/mink-selenium2-driver
    Using version ^2.0 for hpspec/prophecy-phpunit
    Using version ^2.0 for phpspec/prophecy-phpunit
    ```

    # 3- Copy and rename the phpunit.xml file
  7. davidjguru revised this gist Nov 3, 2021. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions drupal_8_9_configure_phpunit_for_testing.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    # Drupal 8 || 9 - Configure your PHPUnit environment for functional testing

    **Author**
    ----------------
    * David Rodríguez, [@davidjguru](https://twitter.com/davidjguru).
  8. davidjguru revised this gist Nov 3, 2021. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions drupal_8_9_configure_phpunit_for_testing.md
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@
    -----------------------
    This snippet was composed from my current position as Senior Drupal Developer at [Digitalist Sweden](https://www.digitalist.se/english), one of the biggest companies oriented to Open Source in Europe and specifically focused in Drupal.

    ## 1- Know your versions
    # 1- Know your versions
    The first step is to know what versions are you using in your Drupal installation. Drupal changes PHPUnit required versions in Drupal 8, Drupal 9 and the PHP installed version.
    For instance, for Drupal 8 deploys you can use PHPUnit 7.x, (7.5.20 in my last test). For Drupal 9 you can use PHPUnit 8.x but if your PHP version is > 7.3 you can use PHPUnit 9.x. So first, get info about Drupal and PHP.

    @@ -32,7 +32,7 @@ $ php -v
    PHP 7.4.20 (cli) (built: Jun 4 2021 23:17:27) ( NTS )
    ```

    ## 2- Resolve dependencies
    # 2- Resolve dependencies

    For my Drupal 9 deploym, I can request something like:

    @@ -63,15 +63,15 @@ Using version ^1.5 for behat/mink-selenium2-driver
    Using version ^2.0 for hpspec/prophecy-phpunit
    ```

    ## 3- Copy and rename the phpunit.xml file
    # 3- Copy and rename the phpunit.xml file

    Locate the file at `/project/web/core/phpunit.xml.dist`. It’s necessary to make a copy of the file and rename it as phpunit.xml

    ```bash
    $ cp /project/web/core/phpunit.xml.dist phpunit.xml
    ```

    ## 4- Set basic values for your phpunit.xml file
    # 4- Set basic values for your phpunit.xml file
    Then, edit the `phpunit.xml` file and set new values in `<php>` section of the file.

    ```php
    @@ -85,7 +85,7 @@ Then, edit the `phpunit.xml` file and set new values in `<php>` section of the f
    </php>
    ```

    ## 5- Connect to the container and check some test in contrib modules
    # 5- Connect to the container and check some test in contrib modules

    ```bash
    $ ddev ssh
  9. davidjguru revised this gist Nov 3, 2021. 1 changed file with 17 additions and 0 deletions.
    17 changes: 17 additions & 0 deletions drupal_8_9_configure_phpunit_for_testing.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,20 @@
    **Author**
    ----------------
    * David Rodríguez, [@davidjguru](https://twitter.com/davidjguru).
    * Contact at [email protected]
    * Website: [https://therussianlullaby.com](https://therussianlullaby.com)
    * Drupal.org profile: [https://www.drupal.org/u/davidjguru](https://www.drupal.org/u/davidjguru)
    * Linkedin profile: [https://www.linkedin.com/in/davidjguru](https://www.linkedin.com/in/davidjguru/)
    * Sketchbook, english: [https://davidjguru.github.io](https://davidjguru.github.io)
    * Medium, spanish: [https://medium.com/@davidjguru](https://medium.com/@davidjguru)
    * Snippets: [https://gitlab.com/users/davidjguru/snippets](https://gitlab.com/users/davidjguru/snippets)
    * Dev.to: [https://dev.to/davidjguru](https://dev.to/davidjguru)


    **Acknowledgments**
    -----------------------
    This snippet was composed from my current position as Senior Drupal Developer at [Digitalist Sweden](https://www.digitalist.se/english), one of the biggest companies oriented to Open Source in Europe and specifically focused in Drupal.

    ## 1- Know your versions
    The first step is to know what versions are you using in your Drupal installation. Drupal changes PHPUnit required versions in Drupal 8, Drupal 9 and the PHP installed version.
    For instance, for Drupal 8 deploys you can use PHPUnit 7.x, (7.5.20 in my last test). For Drupal 9 you can use PHPUnit 8.x but if your PHP version is > 7.3 you can use PHPUnit 9.x. So first, get info about Drupal and PHP.
  10. davidjguru revised this gist Nov 3, 2021. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions drupal_8_9_configure_phpunit_for_testing.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,8 @@
    ## 1- Know your versions
    The first step is to know what versions are you using in your Drupal installation. Drupal changes PHPUnit required versions in Drupal 8, Drupal 9 and the PHP installed version.
    For instance, for Drupal 8 deploys you can use PHPUnit 7.x, (7.5.20 in my last test). For Drupal 9 you can use PHPUnit 8.x but if your PHP version is > 7.3 you can use PHPUnit 9.x. So first, get info about Drupal and PHP.

    [Updated to PHPUnit 9](https://www.drupal.org/node/3176567)
    [See the Issue: Update to PHPUnit 9](https://www.drupal.org/node/3176567)

    ```bash
    $ composer show drupal/core |grep versions
    @@ -15,9 +17,10 @@ PHP 7.4.20 (cli) (built: Jun 4 2021 23:17:27) ( NTS )

    ## 2- Resolve dependencies

    For my Drupal 9 deploym, I can request something like:

    ```bash
    $ composer require --dev phpunit/phpunit:^7 --with-all-dependencies
    $ composer require --dev phpunit/phpunit --with-all-dependencies
    $ composer require --dev symfony/phpunit-bridge
    $ composer require --dev behat/mink-goutte-driver
    $ composer require --dev behat/mink-selenium2-driver
  11. davidjguru revised this gist Nov 3, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion drupal_8_9_configure_phpunit_for_testing.md
    Original file line number Diff line number Diff line change
    @@ -70,7 +70,7 @@ Then, edit the `phpunit.xml` file and set new values in `<php>` section of the f
    ```bash
    $ ddev ssh
    davidjguru@container-web:/var/www/html$ cd web/
    davidjguru@container-web:/var/www/html/web$ ../vendor/bin/phpunit -c core modules/contrib/admin_toolbar
    davidjguru@container-web:/var/www/html/web$ ../vendor/bin/phpunit -c modules/contrib/admin_toolbar
    ```
    Returning:

  12. davidjguru revised this gist Nov 3, 2021. 1 changed file with 8 additions and 2 deletions.
    10 changes: 8 additions & 2 deletions drupal_8_9_configure_phpunit_for_testing.md
    Original file line number Diff line number Diff line change
    @@ -21,24 +21,30 @@ $ composer require --dev phpunit/phpunit:^7 --with-all-dependencies
    $ composer require --dev symfony/phpunit-bridge
    $ composer require --dev behat/mink-goutte-driver
    $ composer require --dev behat/mink-selenium2-driver
    $ composer require --dev phpspec/prophecy-phpunit:^2
    ```

    Or:

    ```bash
    $ composer require --dev phpunit/phpunit symfony/phpunit-bridge \
    behat/mink-goutte-driver behat/mink-selenium2-driver \
    --with-all-dependencies
    phpspec/prophecy-phpunit --with-all-dependencies
    ```
    ```bash

    Getting:

    ```bash
    [...]
    Using version ^9.5 for phpunit/phpunit
    Using version ^5.3 for symfony/phpunit-bridge
    Using version ^1.3 for behat/mink-goutte-driver
    Using version ^1.5 for behat/mink-selenium2-driver
    Using version ^2.0 for hpspec/prophecy-phpunit
    ```

    ## 3- Copy and rename the phpunit.xml file

    Locate the file at `/project/web/core/phpunit.xml.dist`. It’s necessary to make a copy of the file and rename it as phpunit.xml

    ```bash
  13. davidjguru revised this gist Nov 3, 2021. 1 changed file with 29 additions and 5 deletions.
    34 changes: 29 additions & 5 deletions drupal_8_9_configure_phpunit_for_testing.md
    Original file line number Diff line number Diff line change
    @@ -50,12 +50,36 @@ Then, edit the `phpunit.xml` file and set new values in `<php>` section of the f

    ```php
    <php>
    [...]
    <env name="SIMPLETEST_BASE_URL" value="http://localhost"/>
    <env name="SIMPLETEST_DB" value="mysql://username:password@localhost/databasename"/>
    <env name="BROWSERTEST_OUTPUT_DIRECTORY" value="/var/www/html/web/sites/default/simpletest/browser_output/"/>
    <env name="BROWSERTEST_OUTPUT_BASE_URL" value="http://localdeployname.ddev.site/"/>
    [...]
    </php>
    ```

    ## 5- Connect to the container and check some test in contrib modules

    ```bash
    $ ddev ssh
    davidjguru@container-web:/var/www/html$ cd web/
    davidjguru@container-web:/var/www/html/web$ ../vendor/bin/phpunit -c core modules/contrib/admin_toolbar
    ```
    Returning:

    ```bash
    [...]
    <env name="SIMPLETEST_BASE_URL" value="http://localhost"/>
    <env name="SIMPLETEST_DB" value="mysql://username:password@localhost/databasename"/>
    <env name="BROWSERTEST_OUTPUT_DIRECTORY" value="/var/www/html/web/sites/default/simpletest/browser_output/"/>
    <env name="BROWSERTEST_OUTPUT_BASE_URL" value="http://localdeployname.ddev.site/"/>
    PHPUnit 9.5.10 by Sebastian Bergmann and contributors.
    Testing /var/www/html/web/modules/contrib/admin_toolbar
    .SSS.... 8 / 8 (100%)
    Time: 01:01.877, Memory: 6.00 MB

    OK, but incomplete, skipped, or risky tests!
    Tests: 8, Assertions: 110, Skipped: 3.
    [...]
    </php>
    ```

    So, everything is going well! ready to run your own test! **Happy Hacking!**


  14. davidjguru revised this gist Nov 3, 2021. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions drupal_8_9_configure_phpunit_for_testing.md
    Original file line number Diff line number Diff line change
    @@ -50,12 +50,12 @@ Then, edit the `phpunit.xml` file and set new values in `<php>` section of the f

    ```php
    <php>
    [...]
    <env name="SIMPLETEST_BASE_URL" value="http://localhost"/>
    <env name="SIMPLETEST_DB" value="mysql://username:password@localhost/databasename"/>
    <env name="BROWSERTEST_OUTPUT_DIRECTORY" value="/var/www/html/web/sites/default/simpletest/browser_output/"/>
    <env name="BROWSERTEST_OUTPUT_BASE_URL" value="http://localdeployname.ddev.site/"/>
    [...]
    [...]
    <env name="SIMPLETEST_BASE_URL" value="http://localhost"/>
    <env name="SIMPLETEST_DB" value="mysql://username:password@localhost/databasename"/>
    <env name="BROWSERTEST_OUTPUT_DIRECTORY" value="/var/www/html/web/sites/default/simpletest/browser_output/"/>
    <env name="BROWSERTEST_OUTPUT_BASE_URL" value="http://localdeployname.ddev.site/"/>
    [...]
    </php>
    ```

  15. davidjguru created this gist Nov 3, 2021.
    61 changes: 61 additions & 0 deletions drupal_8_9_configure_phpunit_for_testing.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,61 @@
    ## 1- Know your versions

    [Updated to PHPUnit 9](https://www.drupal.org/node/3176567)

    ```bash
    $ composer show drupal/core |grep versions
    versions : * 9.2.7
    ```

    ```bash
    $ php -v

    PHP 7.4.20 (cli) (built: Jun 4 2021 23:17:27) ( NTS )
    ```

    ## 2- Resolve dependencies


    ```bash
    $ composer require --dev phpunit/phpunit:^7 --with-all-dependencies
    $ composer require --dev symfony/phpunit-bridge
    $ composer require --dev behat/mink-goutte-driver
    $ composer require --dev behat/mink-selenium2-driver
    ```

    Or:

    ```bash
    $ composer require --dev phpunit/phpunit symfony/phpunit-bridge \
    behat/mink-goutte-driver behat/mink-selenium2-driver \
    --with-all-dependencies
    ```
    ```bash

    Using version ^9.5 for phpunit/phpunit
    Using version ^5.3 for symfony/phpunit-bridge
    Using version ^1.3 for behat/mink-goutte-driver
    Using version ^1.5 for behat/mink-selenium2-driver
    ```

    ## 3- Copy and rename the phpunit.xml file
    Locate the file at `/project/web/core/phpunit.xml.dist`. It’s necessary to make a copy of the file and rename it as phpunit.xml

    ```bash
    $ cp /project/web/core/phpunit.xml.dist phpunit.xml
    ```

    ## 4- Set basic values for your phpunit.xml file
    Then, edit the `phpunit.xml` file and set new values in `<php>` section of the file.

    ```php
    <php>
    [...]
    <env name="SIMPLETEST_BASE_URL" value="http://localhost"/>
    <env name="SIMPLETEST_DB" value="mysql://username:password@localhost/databasename"/>
    <env name="BROWSERTEST_OUTPUT_DIRECTORY" value="/var/www/html/web/sites/default/simpletest/browser_output/"/>
    <env name="BROWSERTEST_OUTPUT_BASE_URL" value="http://localdeployname.ddev.site/"/>
    [...]
    </php>
    ```