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 (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`
13 #### Install Shaarli dev dependencies
21 #### Install and enable Xdebug to generate PHPUnit coverage reports
23 See http://xdebug.org/docs/install
25 For Debian-based distros:
27 $ aptitude install php5-xdebug
34 Then add the following line to `/etc/php/php.ini`:
36 zend_extension=xdebug.so
41 Successful test suite:
48 PHPUnit 4.6.9 by Sebastian Bergmann and contributors.
50 Configuration read from /home/virtualtam/public_html/shaarli/phpunit.xml
52 ....................................
54 Time: 759 ms, Memory: 8.25Mb
56 OK (36 tests, 65 assertions)
59 Test suite with failures and errors:
65 PHPUnit 4.6.9 by Sebastian Bergmann and contributors.
67 Configuration read from /home/virtualtam/public_html/shaarli/phpunit.xml
69 E..FF...............................
71 Time: 802 ms, Memory: 8.25Mb
75 1) LinkDBTest::testConstructLoggedIn
76 Missing argument 2 for LinkDB::__construct(), called in /home/virtualtam/public_html/shaarli/tests/Link\
77 DBTest.php on line 79 and defined
79 /home/virtualtam/public_html/shaarli/application/LinkDB.php:58
80 /home/virtualtam/public_html/shaarli/tests/LinkDBTest.php:79
84 There were 2 failures:
86 1) LinkDBTest::testCheckDBNew
87 Failed asserting that two strings are equal.
91 -'e3edea8ea7bb50be4bcb404df53fbb4546a7156e'
92 +'85eab0c610d4f68025f6ed6e6b6b5fabd4b55834'
94 /home/virtualtam/public_html/shaarli/tests/LinkDBTest.php:121
96 2) LinkDBTest::testCheckDBLoad
97 Failed asserting that two strings are equal.
101 -'e3edea8ea7bb50be4bcb404df53fbb4546a7156e'
102 +'85eab0c610d4f68025f6ed6e6b6b5fabd4b55834'
104 /home/virtualtam/public_html/shaarli/tests/LinkDBTest.php:133
107 Tests: 36, Assertions: 63, Errors: 1, Failures: 2.
110 #### Test results and coverage
112 By default, PHPUnit will run all suitable tests found under the `tests` directory.
114 Each test has 3 possible outcomes:
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
124 If Xdebug has been installed and activated, two coverage reports will be generated:
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 &`
130 ### Executing specific tests
132 Add a [`@group`](https://phpunit.de/manual/current/en/appendixes.annotations.html#appendixes.annotations.group) annotation in a test class or method comment:
136 * Netscape bookmark import
139 class BookmarkImportTest extends PHPUnit_Framework_TestCase
145 To run all tests annotated with `@group WIP`:
147 $ vendor/bin/phpunit --group WIP tests/