drupal-module-tdd-blog/README.md

56 lines
1.9 KiB
Markdown
Raw Normal View History

2018-04-19 22:29:38 +00:00
# TDD Example Drupal 8 Module for DrupalCamp Dublin
2017-10-21 14:12:25 +00:00
2017-10-21 20:50:37 +00:00
A demo module to accompany my [TDD - Test Driven Drupal][0] talk at 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
- I want to see a list of all published pages at `/pages`
- Ordered alphabetically by title
2018-04-03 07:46:46 +00:00
## Installation
Within your Drupal 8 site:
```bash
cd modules
2018-04-19 22:29:38 +00:00
git clone git@github.com:opdavies/drupal-module-tdd-dublin.git tdd_dublin
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
named `tdd_dublin` as per the repository name.
```
2017-11-07 01:08:47 +00:00
vendor/bin/phpunit -c core modules/custom/tdd_dublin
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:
```
2017-11-07 01:08:47 +00:00
vendor/bin/phpunit -c core modules/custom/tdd_dublin --filter=testOnlyPublishedPagesAreShown
2017-10-21 14:12:25 +00:00
```
2018-04-19 22:29:38 +00:00
[0]: https://www.oliverdavi.es/talks/tdd-test-driven-drupal
2017-10-21 21:08:42 +00:00
[1]: https://github.com/opdavies/tdd_dublin/commits/HEAD
[2]: https://github.com/opdavies/tdd_dublin/tags