As part of a larger initiative to modernize the testing system and move to PHPUnit as the runner for all of our tests,
These are Mink based browser implementations using the Goutte-based driver (Goutte (friendsofphp/goutte) is basically guzzle/guzzlehttp and symfony/domcrawler). This allows us to use industry standard PHP libraries for simulating a browser and opens the door for further steps, eg.of the planned testing roadmap.
You are free to use them for your contrib projects, seefor example.
For new tests, use the new base classes. For older tests, seefor the larger conversion process.
Kudos to Simpletest
Simpletest has provided us with the means to make the wide-ranging changes we've made in Drupal 8. Without a test-framework we'd have been flying blind performing the level of refactoring we've done in Drupal 8. But throughout the Drupal 8 cycle, poor old Simpletest hasn't gotten the same level of love as other parts of core. This is part of the plan to spread some love to our testing APIs, modernize them and bring them in to line with the wider PHP community.
But my contrib tests are written with Simpletest!
Don't worry, Simpletest will need to be supported for Drupal 8, removing it would be an API break.
Converting your contrib tests
- Update your class to extend from
Move your test from the src/Tests folder (Drupal\yourmodule\Tests namespace) to the tests/src/Functional (Drupal\Tests\yourmodule\Functional namespace)
- Update your asserts as per the table
|Before (Simpletest/WebTestBase)||After (Phpunit/Mink)|
|drupalPostForm($url, $values, $button_text);||submitForm($values, $button_text);|
Running your contrib tests
$ cd core $ sudo -u www-data SIMPLETEST_BASE_URL=http://yourd8.url ./vendor/bin/phpunit --testsuite functional --group yourmodule # Or with run-test $ sudo -u www-data php ./core/scripts/run-tests.sh --url http://yourd8.url --class "Drupal\Tests\yourmodule\Functional\YourModuleTest"
With that change we have now both a very fast test suite ("unit") and a slower one ("functional").
If you just use:
both will be executed.
For development you probably want to separate the execution, so to execute both in isolation use:
./vendor/bin/phpunit --testsuite unit
as well as
./vendor/bin/phpunit --testsuite functional