Skip to content

Instantly share code, notes, and snippets.

@cosmicdreams
Last active March 11, 2023 18:54
Show Gist options
  • Save cosmicdreams/071fee67c9b689743da25e54bb7ee3d4 to your computer and use it in GitHub Desktop.
Save cosmicdreams/071fee67c9b689743da25e54bb7ee3d4 to your computer and use it in GitHub Desktop.
Instructions for adding DDEV into your project so you can run tests.

Install DDEV so you can run tests

Steps to get tests running

  1. Install all the things
  2. Fix PHP path mappings
  3. Configure phpunit

Prerequisites

Install Colima or keep using Docker Desktop

Mac:

  • brew install docker
  • brew install colima
  • run colima: colima start --cpu 4 --memory 6 --disk 100 --vm-type=qemu --mount-type=sshfs --dns=1.1.1.1 Windows

Install DDEV

Mac:

  • brew install ddev/ddev/ddev
  • mkcert -install

Install the DDEV PhpStorm Plugin

https://plugins.jetbrains.com/plugin/18813-ddev-integration

Set up a project for Tests

  1. cd ~/Sites
  2. mkdir my-drupal10-site
  3. cd my-drupal10-site
  4. ddev config --project-type=drupal10 --docroot=web --create-docroot
  5. ddev get ddev/ddev-selenium-standalone-chrome
  6. ddev start
  7. ddev composer create drupal/recommended-project
  8. ddev composer require drupal/core-dev --dev --update-with-all-dependencies
  9. ddev composer require drush/drush
  10. ddev drush site:install --account-name=admin --account-pass=admin -y
  11. ddev drush uli
  12. ddev launch

Existing Project

  1. Navigate to the root of your projct in a terminal
  2. ddev config --project-type=drupal10 --docroot=web # or another one of the project types
  3. ddev get ddev/ddev-selenium-standalone-chrome
  4. ddev composer require drupal/core-dev --dev --update-with-all-dependencies
  5. ddev start

Optimize performance

  • ddev config --mutagen-enabled=true
  • ddev start

Configure PhpStorm to run tests

  1. In PhpStorm, open the project and open preferences
  2. Navigate to PHP
  3. Fix file paths by adding a new path mapping. 4. Local Path: /Users/yourusername/Sites/my-drupal10-site 5. Remote Path: /var/www/html
  4. Navigate to PHP > Test Frameworks
  5. Add a new PHPUnit configuration and use the Remote PHP Interpreter that the DDEV plugin setup for you.
  6. Choose to find phpunit by PHAR file path.
  7. Set path to phpunit to be /var/www/html/vendor/bin/phpunit
  8. Set the configuration file to be /var/www/html/web/core/phpunit.xml.dist

Test if test work via command line

  • Unit ddev exec phpunit -c /var/www/html/web/core/phpunit.xml.dist /var/www/html/web/core/modules/system/tests/src/Unit/Routing/AdminRouteSubscriberTest.php
  • Kernel ddev exec phpunit -c /var/www/html/web/core/phpunit.xml.dist /var/www/html/web/core/modules/node/tests/src/Kernel/NodeAccessTest.php
  • Functional ddev exec phpunit -c /var/www/html/web/core/phpunit.xml.dist /var/www/html/web/core/modules/node/tests/src/Functional/NodeAccessCacheabilityWithNodeGrants.php
  • FunctionalJavascript ddev exec phpunit -c /var/www/html/web/core/phpunit.xml.dist /var/www/html/web/core/modules/node/tests/src/FunctionalJavascript/NodePreviewLinkTest.php

Run tests in PhpStorm

Navigate to each test file and click the green play button to run the test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment