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.
5 Regarding Composer, you can either use:
7 - a system-wide version, e.g. installed through your distro's package manager
8 - 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 For Debian-based distros:
34 $ aptitude install php5-xdebug
41 Then add the following line to `/etc/php/php.ini`:
43 zend_extension=xdebug.so
48 Successful test suite:
55 PHPUnit 4.6.9 by Sebastian Bergmann and contributors.
57 Configuration read from /home/virtualtam/public_html/shaarli/phpunit.xml
59 ....................................
61 Time: 759 ms, Memory: 8.25Mb
63 OK (36 tests, 65 assertions)
66 Test suite with failures and errors:
72 PHPUnit 4.6.9 by Sebastian Bergmann and contributors.
74 Configuration read from /home/virtualtam/public_html/shaarli/phpunit.xml
76 E..FF...............................
78 Time: 802 ms, Memory: 8.25Mb
82 1) LinkDBTest::testConstructLoggedIn
83 Missing argument 2 for LinkDB::__construct(), called in /home/virtualtam/public_html/shaarli/tests/Link\
84 DBTest.php on line 79 and defined
86 /home/virtualtam/public_html/shaarli/application/LinkDB.php:58
87 /home/virtualtam/public_html/shaarli/tests/LinkDBTest.php:79
91 There were 2 failures:
93 1) LinkDBTest::testCheckDBNew
94 Failed asserting that two strings are equal.
98 -'e3edea8ea7bb50be4bcb404df53fbb4546a7156e'
99 +'85eab0c610d4f68025f6ed6e6b6b5fabd4b55834'
101 /home/virtualtam/public_html/shaarli/tests/LinkDBTest.php:121
103 2) LinkDBTest::testCheckDBLoad
104 Failed asserting that two strings are equal.
108 -'e3edea8ea7bb50be4bcb404df53fbb4546a7156e'
109 +'85eab0c610d4f68025f6ed6e6b6b5fabd4b55834'
111 /home/virtualtam/public_html/shaarli/tests/LinkDBTest.php:133
114 Tests: 36, Assertions: 63, Errors: 1, Failures: 2.
117 #### Test results and coverage
119 By default, PHPUnit will run all suitable tests found under the `tests` directory.
121 Each test has 3 possible outcomes:
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
131 If Xdebug has been installed and activated, two coverage reports will be generated:
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 &`
137 ### Executing specific tests
139 Add a [`@group`](https://phpunit.de/manual/current/en/appendixes.annotations.html#appendixes.annotations.group) annotation in a test class or method comment:
143 * Netscape bookmark import
146 class BookmarkImportTest extends PHPUnit_Framework_TestCase
152 To run all tests annotated with `@group WIP`:
154 $ vendor/bin/phpunit --group WIP tests/