]> git.immae.eu Git - github/shaarli/Shaarli.git/blame - doc/md/Unit-tests.md
doc: simplify unit tests documentation
[github/shaarli/Shaarli.git] / doc / md / Unit-tests.md
CommitLineData
da9b0e3e 1### Setup your environment for tests
53ed6d7d 2
3The framework used is [PHPUnit](https://phpunit.de/); it can be installed with [Composer](https://getcomposer.org/), which is a dependency management tool.
da9b0e3e 4
76c3a4db 5### Install composer
43ad7c8e 6
76c3a4db 7You can either use:
da9b0e3e 8
6fa3c87d 9- a system-wide version, e.g. installed through your distro's package manager (eg. `sudo apt install composer`)
10- a local version, downloadable [here](https://getcomposer.org/download/). To update a local composer installation, run `php composer.phar self-update`
53ed6d7d 11
da9b0e3e 12
13#### Install Shaarli dev dependencies
53ed6d7d 14
da9b0e3e 15```bash
16$ cd /path/to/shaarli
6fa3c87d 17$ composer install
da9b0e3e 18$ composer update
19```
20
21#### Install and enable Xdebug to generate PHPUnit coverage reports
53ed6d7d 22
76c3a4db 23See http://xdebug.org/docs/install
24
da9b0e3e 25```bash
7a7a5237 26# for Debian-based distributions
da9b0e3e 27$ aptitude install php5-xdebug
7a7a5237 28
29# for ArchLinux:
da9b0e3e 30$ pacman -S xdebug
31```
32
33Then add the following line to `/etc/php/php.ini`:
34```ini
35zend_extension=xdebug.so
36```
37
38#### Run unit tests
53ed6d7d 39
7a7a5237 40Run `make test` and ensure tests return `OK`. If tests return failures, refer to PHPUnit messages and fix your code/tests accordingly.
da9b0e3e 41
da9b0e3e 42
43#### Test results and coverage
53ed6d7d 44
da9b0e3e 45By default, PHPUnit will run all suitable tests found under the `tests` directory.
46
47Each test has 3 possible outcomes:
43ad7c8e
V
48
49- `.` - success
50- `F` - failure: the test was run but its results are invalid
51 - the code does not behave as expected
52 - dependencies to external elements: globals, session, cache...
53- `E` - error: something went wrong and the tested code has crashed
54 - typos in the code, or in the test code
55 - dependencies to missing external elements
da9b0e3e 56
57If Xdebug has been installed and activated, two coverage reports will be generated:
43ad7c8e
V
58
59- a summary in the console
60- a detailed HTML report with metrics for tested code
61 - to open it in a web browser: `firefox coverage/index.html &`
b230bf20
A
62
63### Executing specific tests
53ed6d7d 64
65Add a [`@group`](https://phpunit.de/manual/current/en/appendixes.annotations.html#appendixes.annotations.group) annotation in a test class or method comment:
b230bf20
A
66
67```php
68/**
69 * Netscape bookmark import
70 * @group WIP
71 */
72class BookmarkImportTest extends PHPUnit_Framework_TestCase
73{
53ed6d7d 74 [...]
b230bf20
A
75}
76```
77
78To run all tests annotated with `@group WIP`:
79```bash
80$ vendor/bin/phpunit --group WIP tests/
81```