]> git.immae.eu Git - github/shaarli/Shaarli.git/blame - doc/md/Unit-tests.md
documentation: fix rendering and internal references
[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
5Regarding Composer, you can either use:
43ad7c8e
V
6
7- a system-wide version, e.g. installed through your distro's package manager
8- a local version, downloadable [here](https://getcomposer.org/download/)
da9b0e3e 9
10#### Sample usage
53ed6d7d 11
da9b0e3e 12```bash
13# system-wide version
14$ composer install
15$ composer update
16
17# local version
18$ php composer.phar self-update
19$ php composer.phar install
20$ php composer.phar update
21```
22
23#### Install Shaarli dev dependencies
53ed6d7d 24
da9b0e3e 25```bash
26$ cd /path/to/shaarli
27$ composer update
28```
29
30#### Install and enable Xdebug to generate PHPUnit coverage reports
53ed6d7d 31
da9b0e3e 32For Debian-based distros:
33```bash
34$ aptitude install php5-xdebug
35```
36For ArchLinux:
37```bash
38$ pacman -S xdebug
39```
40
41Then add the following line to `/etc/php/php.ini`:
42```ini
43zend_extension=xdebug.so
44```
45
46#### Run unit tests
53ed6d7d 47
da9b0e3e 48Successful test suite:
49```bash
50$ make test
51
52-------
53PHPUNIT
54-------
55PHPUnit 4.6.9 by Sebastian Bergmann and contributors.
56
57Configuration read from /home/virtualtam/public_html/shaarli/phpunit.xml
58
59....................................
60
61Time: 759 ms, Memory: 8.25Mb
62
63OK (36 tests, 65 assertions)
64```
65
66Test suite with failures and errors:
67```bash
68$ make test
69-------
70PHPUNIT
71-------
72PHPUnit 4.6.9 by Sebastian Bergmann and contributors.
73
74Configuration read from /home/virtualtam/public_html/shaarli/phpunit.xml
75
76E..FF...............................
77
78Time: 802 ms, Memory: 8.25Mb
79
80There was 1 error:
81
821) LinkDBTest::testConstructLoggedIn
83Missing argument 2 for LinkDB::__construct(), called in /home/virtualtam/public_html/shaarli/tests/Link\
84DBTest.php on line 79 and defined
85
86/home/virtualtam/public_html/shaarli/application/LinkDB.php:58
87/home/virtualtam/public_html/shaarli/tests/LinkDBTest.php:79
88
89--
90
91There were 2 failures:
92
931) LinkDBTest::testCheckDBNew
94Failed asserting that two strings are equal.
95--- Expected
96+++ Actual
97@@ @@
98-'e3edea8ea7bb50be4bcb404df53fbb4546a7156e'
99+'85eab0c610d4f68025f6ed6e6b6b5fabd4b55834'
100
101/home/virtualtam/public_html/shaarli/tests/LinkDBTest.php:121
102
1032) LinkDBTest::testCheckDBLoad
104Failed asserting that two strings are equal.
105--- Expected
106+++ Actual
107@@ @@
108-'e3edea8ea7bb50be4bcb404df53fbb4546a7156e'
109+'85eab0c610d4f68025f6ed6e6b6b5fabd4b55834'
110
111/home/virtualtam/public_html/shaarli/tests/LinkDBTest.php:133
112
113FAILURES!
114Tests: 36, Assertions: 63, Errors: 1, Failures: 2.
115```
116
117#### Test results and coverage
53ed6d7d 118
da9b0e3e 119By default, PHPUnit will run all suitable tests found under the `tests` directory.
120
121Each test has 3 possible outcomes:
43ad7c8e
V
122
123- `.` - success
124- `F` - failure: the test was run but its results are invalid
125 - the code does not behave as expected
126 - dependencies to external elements: globals, session, cache...
127- `E` - error: something went wrong and the tested code has crashed
128 - typos in the code, or in the test code
129 - dependencies to missing external elements
da9b0e3e 130
131If Xdebug has been installed and activated, two coverage reports will be generated:
43ad7c8e
V
132
133- a summary in the console
134- a detailed HTML report with metrics for tested code
135 - to open it in a web browser: `firefox coverage/index.html &`
b230bf20
A
136
137### Executing specific tests
53ed6d7d 138
139Add a [`@group`](https://phpunit.de/manual/current/en/appendixes.annotations.html#appendixes.annotations.group) annotation in a test class or method comment:
b230bf20
A
140
141```php
142/**
143 * Netscape bookmark import
144 * @group WIP
145 */
146class BookmarkImportTest extends PHPUnit_Framework_TestCase
147{
53ed6d7d 148 [...]
b230bf20
A
149}
150```
151
152To run all tests annotated with `@group WIP`:
153```bash
154$ vendor/bin/phpunit --group WIP tests/
155```