drupal-module-tdd-blog/README.md

56 lines
1.9 KiB
Markdown
Raw Normal View History

2020-03-07 20:13:13 +00:00
# TDD Example Drupal 8 Blog Module
2017-10-21 14:12:25 +00:00
2020-03-07 20:13:13 +00:00
A demo module to accompany my [TDD - Test Driven Drupal][0] talk, originally for DrupalCamp
2017-10-21 14:12:25 +00:00
Dublin 2017.
2017-10-21 21:08:42 +00:00
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][1] and see each step taken, as well as
[the tags][2] that identify the commits when each failing test is added and
then subsequently passes.
2017-10-21 14:12:25 +00:00
## 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
2018-09-07 17:33:14 +00:00
- I want to see a list of all published blog posts at `/blog`
- Ordered by post date, with the newest posts first
2017-10-21 14:12:25 +00:00
2018-04-03 07:46:46 +00:00
## Installation
Within your Drupal 8 site:
```bash
cd modules
2018-09-07 17:33:14 +00:00
git clone git@github.com:opdavies/drupal-module-tdd-blog.git tdd_blog
2018-04-03 07:46:46 +00:00
```
2017-10-21 14:12:25 +00:00
## 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.
2017-11-07 01:08:47 +00:00
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.
2017-10-21 14:12:25 +00:00
This also assumes that the module is within a `modules/custom` directory and
2018-09-07 17:33:14 +00:00
named `tdd_blog` as per the repository name.
2017-10-21 14:12:25 +00:00
```
2018-09-07 17:33:14 +00:00
vendor/bin/phpunit -c core modules/custom/tdd_blog
2017-10-21 14:12:25 +00:00
```
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:
```
2018-09-07 17:33:14 +00:00
vendor/bin/phpunit -c core modules/custom/tdd_blog --filter=testOnlyPublishedPagesAreShown
2017-10-21 14:12:25 +00:00
```
2018-09-07 17:33:14 +00:00
[0]: https://www.oliverdavies.uk/talks/tdd-test-driven-drupal
[1]: https://github.com/opdavies/drupal-module-tdd-blog/commits/HEAD
[2]: https://github.com/opdavies/drupal-module-tdd-blog/tags