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:
6 * a system-wide version, e.g. installed through your distro's package manager
7 * a local version, downloadable [here](https://getcomposer.org/download/)
17 $ php composer.phar self-update
18 $ php composer.phar install
19 $ php composer.phar update
22 #### Install Shaarli dev dependencies
29 #### Install and enable Xdebug to generate PHPUnit coverage reports
31 For Debian-based distros:
33 $ aptitude install php5-xdebug
40 Then add the following line to `/etc/php/php.ini`:
42 zend_extension=xdebug.so
47 Successful test suite:
54 PHPUnit 4.6.9 by Sebastian Bergmann and contributors.
56 Configuration read from /home/virtualtam/public_html/shaarli/phpunit.xml
58 ....................................
60 Time: 759 ms, Memory: 8.25Mb
62 OK (36 tests, 65 assertions)
65 Test suite with failures and errors:
71 PHPUnit 4.6.9 by Sebastian Bergmann and contributors.
73 Configuration read from /home/virtualtam/public_html/shaarli/phpunit.xml
75 E..FF...............................
77 Time: 802 ms, Memory: 8.25Mb
81 1) LinkDBTest::testConstructLoggedIn
82 Missing argument 2 for LinkDB::__construct(), called in /home/virtualtam/public_html/shaarli/tests/Link\
83 DBTest.php on line 79 and defined
85 /home/virtualtam/public_html/shaarli/application/LinkDB.php:58
86 /home/virtualtam/public_html/shaarli/tests/LinkDBTest.php:79
90 There were 2 failures:
92 1) LinkDBTest::testCheckDBNew
93 Failed asserting that two strings are equal.
97 -'e3edea8ea7bb50be4bcb404df53fbb4546a7156e'
98 +'85eab0c610d4f68025f6ed6e6b6b5fabd4b55834'
100 /home/virtualtam/public_html/shaarli/tests/LinkDBTest.php:121
102 2) LinkDBTest::testCheckDBLoad
103 Failed asserting that two strings are equal.
107 -'e3edea8ea7bb50be4bcb404df53fbb4546a7156e'
108 +'85eab0c610d4f68025f6ed6e6b6b5fabd4b55834'
110 /home/virtualtam/public_html/shaarli/tests/LinkDBTest.php:133
113 Tests: 36, Assertions: 63, Errors: 1, Failures: 2.
116 #### Test results and coverage
118 By default, PHPUnit will run all suitable tests found under the `tests` directory.
120 Each test has 3 possible outcomes:
122 * `F` - failure: the test was run but its results are invalid
123 * the code does not behave as expected
124 * dependencies to external elements: globals, session, cache...
125 * `E` - error: something went wrong and the tested code has crashed
126 * typos in the code, or in the test code
127 * dependencies to missing external elements
129 If Xdebug has been installed and activated, two coverage reports will be generated:
130 * a summary in the console
131 * a detailed HTML report with metrics for tested code
132 * to open it in a web browser: `firefox coverage/index.html &`
134 ### Executing specific tests
136 Add a [`@group`](https://phpunit.de/manual/current/en/appendixes.annotations.html#appendixes.annotations.group) annotation in a test class or method comment:
140 * Netscape bookmark import
143 class BookmarkImportTest extends PHPUnit_Framework_TestCase
149 To run all tests annotated with `@group WIP`:
151 $ vendor/bin/phpunit --group WIP tests/