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