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