1 ### Setup your environment for tests
3 The framework used is [PHPUnit](https://phpunit.de/); it can be installed with [Composer](https://getcomposer.org/), which is a dependency management tool.
9 - a system-wide version, e.g. installed through your distro's package manager
10 - a local version, downloadable [here](https://getcomposer.org/download/).
18 $ php composer.phar self-update
19 $ php composer.phar install
20 $ php composer.phar update
23 #### Install Shaarli dev dependencies
30 #### Install and enable Xdebug to generate PHPUnit coverage reports
32 See http://xdebug.org/docs/install
34 For Debian-based distros:
36 $ aptitude install php5-xdebug
43 Then add the following line to `/etc/php/php.ini`:
45 zend_extension=xdebug.so
50 Successful test suite:
57 PHPUnit 4.6.9 by Sebastian Bergmann and contributors.
59 Configuration read from /home/virtualtam/public_html/shaarli/phpunit.xml
61 ....................................
63 Time: 759 ms, Memory: 8.25Mb
65 OK (36 tests, 65 assertions)
68 Test suite with failures and errors:
74 PHPUnit 4.6.9 by Sebastian Bergmann and contributors.
76 Configuration read from /home/virtualtam/public_html/shaarli/phpunit.xml
78 E..FF...............................
80 Time: 802 ms, Memory: 8.25Mb
84 1) LinkDBTest::testConstructLoggedIn
85 Missing argument 2 for LinkDB::__construct(), called in /home/virtualtam/public_html/shaarli/tests/Link\
86 DBTest.php on line 79 and defined
88 /home/virtualtam/public_html/shaarli/application/LinkDB.php:58
89 /home/virtualtam/public_html/shaarli/tests/LinkDBTest.php:79
93 There were 2 failures:
95 1) LinkDBTest::testCheckDBNew
96 Failed asserting that two strings are equal.
100 -'e3edea8ea7bb50be4bcb404df53fbb4546a7156e'
101 +'85eab0c610d4f68025f6ed6e6b6b5fabd4b55834'
103 /home/virtualtam/public_html/shaarli/tests/LinkDBTest.php:121
105 2) LinkDBTest::testCheckDBLoad
106 Failed asserting that two strings are equal.
110 -'e3edea8ea7bb50be4bcb404df53fbb4546a7156e'
111 +'85eab0c610d4f68025f6ed6e6b6b5fabd4b55834'
113 /home/virtualtam/public_html/shaarli/tests/LinkDBTest.php:133
116 Tests: 36, Assertions: 63, Errors: 1, Failures: 2.
119 #### Test results and coverage
121 By default, PHPUnit will run all suitable tests found under the `tests` directory.
123 Each test has 3 possible outcomes:
126 - `F` - failure: the test was run but its results are invalid
127 - the code does not behave as expected
128 - dependencies to external elements: globals, session, cache...
129 - `E` - error: something went wrong and the tested code has crashed
130 - typos in the code, or in the test code
131 - dependencies to missing external elements
133 If Xdebug has been installed and activated, two coverage reports will be generated:
135 - a summary in the console
136 - a detailed HTML report with metrics for tested code
137 - to open it in a web browser: `firefox coverage/index.html &`
139 ### Executing specific tests
141 Add a [`@group`](https://phpunit.de/manual/current/en/appendixes.annotations.html#appendixes.annotations.group) annotation in a test class or method comment:
145 * Netscape bookmark import
148 class BookmarkImportTest extends PHPUnit_Framework_TestCase
154 To run all tests annotated with `@group WIP`:
156 $ vendor/bin/phpunit --group WIP tests/