A demo module for DrupalCamp Dublin to show test driven module development.
Find a file
2020-03-07 20:15:32 +00:00
config/install Update node.type.article.yml 2019-03-02 11:13:16 +00:00
tests/src Use constant for the response code 2020-03-07 17:16:50 +00:00
.gitignore Get the result of the view 2017-10-30 10:44:15 +00:00
composer.json Change to tdd_blog 2018-09-07 18:33:14 +01:00
README.md Update README.md 2020-03-07 20:15:32 +00:00
tdd_blog.info.yml Add core_version_requirement 2020-03-07 17:17:32 +00:00

TDD Example Drupal 8 Blog Module

A demo module to accompany my TDD - Test Driven Drupal talk, originally for DrupalCamp Dublin 2017.

In order to see my workflow of writing comments first, converting them into failing tests, and then writing the implementation code to make them pass, you can see the list of previous commits and see each step taken, as well as the tags that identify the commits when each failing test is added and then subsequently passes.

Acceptance Criteria

This module will be used to demonstrate how to take a test-driven approach to develop a module to the following acceptance criteria:

  • As a site visitor
  • I want to see a list of all published blog posts at /blog
  • Ordered by post date, with the newest posts first

Installation

Within your Drupal 8 site:

cd modules
git clone git@github.com:opdavies/drupal-module-tdd-blog.git tdd_blog

Running the Tests

These tests are functional tests based on the BrowserTestBase class so need to be executed with PHPUnit (which is required in core's composer.json file). The path to your vendor directory may be different depending on your setup.

Because of autoloading, you will either need to be inside Drupal's core subdirectory , or add -c core to the PHPUnit command when running the tests for them to execute successfully.

This also assumes that the module is within a modules/custom directory and named tdd_blog as per the repository name.

vendor/bin/phpunit -c core modules/custom/tdd_blog

You can use PHPUnit's --filter option to specify a single test method to run, rather than all of the tests within the module. For example:

vendor/bin/phpunit -c core modules/custom/tdd_blog --filter=testOnlyPublishedPagesAreShown