Robo task runner setup steps, for use in Lando environment.
lando composer require --dev drupal/coder \
kerasai/robo-drupal \
kerasai/robo-phpcs \
mglaman/phpstan-drupal \
phpstan/extension-installer \
phpstan/phpstan \
phpstan/phpstan-deprecation-rules
Add tooling to .lando.yml
tooling:
robo:
service: appserver
description: Runs Robo commands
cmd: /app/vendor/bin/robo
lando robo init
Replace Robofile.php
with file below. Update to use the proper environment detection class.
Add robo.yml
with file below.
lando composer require --dev \
behat/mink-browserkit-driver \
phpunit/phpunit \
weitzman/drupal-test-traits
Add testing namespace to composer.json
:
"autoload": {
"psr-4": {
"MyProject\\": "src/",
"MyProjectTests\\": "tests/"
}
},
Create a phpunit.xml
based on https://git.drupalcode.org/project/dtt/-/blob/2.x/docs/phpunit.xml.
Set the DTT_BASE_URL
environment variable in the .lando.yml
:
services:
appserver:
overrides:
environment:
DTT_BASE_URL: "https://__mysite__.lndo.site"
Add Robo commands:
/**
* Unit tests
*/
public function testUnit() {
return $this->taskExec('vendor/bin/phpunit --testsuite=unit');
}
/**
* Kernel tests
*/
public function testKernel() {
return $this->taskExec('vendor/bin/phpunit --testsuite=kernel');
}
/**
* Existing site tests
*/
public function testExistingSite() {
return $this->taskExec('vendor/bin/phpunit --testsuite=existing-site');
}
/**
* Existing site JS tests
*/
public function testExistingSiteJavascript() {
return $this->taskExec('vendor/bin/phpunit --testsuite=existing-site-javascript');
}
Run DTT test commands in robo test
:
$collection->addTask($this->testUnit())
->addTask($this->testKernel())
->addTask($this->testExistingSite())
->addTask($this->testExistingSiteJavascript());
Add tooling to .lando.yml
:
tooling:
phpunit:
service: appserver
description: Runs PHPUnit
cmd: /app/vendor/bin/phpunit
mkdir -p tests/src/ExistingSite
touch tests/src/ExistingSite/HomepageTest.php
Copy in the contents of HomepageTest.php
below. Add the directory to the testsuite defined in phpunit.xml
:
<directory>./tests/src/ExistingSite</directory>
You may also use drush
to generate classes for writing tests:
drush generate test:existing
or drush generate test:existing-js