aboutsummaryrefslogtreecommitdiffhomepage
path: root/doc/md/Unit-tests.md
diff options
context:
space:
mode:
Diffstat (limited to 'doc/md/Unit-tests.md')
-rw-r--r--doc/md/Unit-tests.md158
1 files changed, 60 insertions, 98 deletions
diff --git a/doc/md/Unit-tests.md b/doc/md/Unit-tests.md
index f6030d5c..a9544656 100644
--- a/doc/md/Unit-tests.md
+++ b/doc/md/Unit-tests.md
@@ -1,126 +1,45 @@
1### Setup your environment for tests 1The testing framework used is [PHPUnit](https://phpunit.de/); it can be installed with [Composer](https://getcomposer.org/), which is a dependency management tool.
2 2
3The framework used is [PHPUnit](https://phpunit.de/); it can be installed with [Composer](https://getcomposer.org/), which is a dependency management tool. 3## Setup a testing environment
4 4
5### Install composer 5### Install composer
6 6
7You can either use: 7You can either use:
8 8
9- a system-wide version, e.g. installed through your distro's package manager 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/). 10- a local version, downloadable [here](https://getcomposer.org/download/). To update a local composer installation, run `php composer.phar self-update`
11 11
12```bash
13# system-wide version
14$ composer install
15$ composer update
16
17# local version
18$ php composer.phar self-update
19$ php composer.phar install
20$ php composer.phar update
21```
22 12
23#### Install Shaarli dev dependencies 13### Install Shaarli development dependencies
24 14
25```bash 15```bash
26$ cd /path/to/shaarli 16$ cd /path/to/shaarli
27$ composer update 17$ composer install
28``` 18```
29 19
30#### Install and enable Xdebug to generate PHPUnit coverage reports 20### Install Xdebug
31 21
32See http://xdebug.org/docs/install 22Xdebug must be installed and enable for PHPUnit to generate coverage reports. See http://xdebug.org/docs/install.
33 23
34For Debian-based distros:
35```bash
36$ aptitude install php5-xdebug
37```
38For ArchLinux:
39```bash 24```bash
25# for Debian-based distributions
26$ aptitude install php-xdebug
27
28# for ArchLinux:
40$ pacman -S xdebug 29$ pacman -S xdebug
41``` 30```
42 31
43Then add the following line to `/etc/php/php.ini`: 32Then add the following line to `/etc/php/<PHP_VERSION>/cli/php.ini`:
33
44```ini 34```ini
45zend_extension=xdebug.so 35zend_extension=xdebug.so
46``` 36```
47 37
48#### Run unit tests 38## Run unit tests
49
50Successful test suite:
51```bash
52$ make test
53
54-------
55PHPUNIT
56-------
57PHPUnit 4.6.9 by Sebastian Bergmann and contributors.
58
59Configuration read from /home/virtualtam/public_html/shaarli/phpunit.xml
60
61....................................
62
63Time: 759 ms, Memory: 8.25Mb
64
65OK (36 tests, 65 assertions)
66```
67
68Test suite with failures and errors:
69```bash
70$ make test
71-------
72PHPUNIT
73-------
74PHPUnit 4.6.9 by Sebastian Bergmann and contributors.
75
76Configuration read from /home/virtualtam/public_html/shaarli/phpunit.xml
77
78E..FF...............................
79
80Time: 802 ms, Memory: 8.25Mb
81
82There was 1 error:
83
841) LinkDBTest::testConstructLoggedIn
85Missing argument 2 for LinkDB::__construct(), called in /home/virtualtam/public_html/shaarli/tests/Link\
86DBTest.php on line 79 and defined
87
88/home/virtualtam/public_html/shaarli/application/LinkDB.php:58
89/home/virtualtam/public_html/shaarli/tests/LinkDBTest.php:79
90
91--
92
93There were 2 failures:
94
951) LinkDBTest::testCheckDBNew
96Failed asserting that two strings are equal.
97--- Expected
98+++ Actual
99@@ @@
100-'e3edea8ea7bb50be4bcb404df53fbb4546a7156e'
101+'85eab0c610d4f68025f6ed6e6b6b5fabd4b55834'
102
103/home/virtualtam/public_html/shaarli/tests/LinkDBTest.php:121
104
1052) LinkDBTest::testCheckDBLoad
106Failed asserting that two strings are equal.
107--- Expected
108+++ Actual
109@@ @@
110-'e3edea8ea7bb50be4bcb404df53fbb4546a7156e'
111+'85eab0c610d4f68025f6ed6e6b6b5fabd4b55834'
112
113/home/virtualtam/public_html/shaarli/tests/LinkDBTest.php:133
114
115FAILURES!
116Tests: 36, Assertions: 63, Errors: 1, Failures: 2.
117```
118
119#### Test results and coverage
120 39
121By default, PHPUnit will run all suitable tests found under the `tests` directory. 40Run `make test` and ensure tests return `OK`. If tests return failures, refer to PHPUnit messages and fix your code/tests accordingly.
122 41
123Each test has 3 possible outcomes: 42By default, PHPUnit will run all suitable tests found under the `tests` directory. Each test has 3 possible outcomes:
124 43
125- `.` - success 44- `.` - success
126- `F` - failure: the test was run but its results are invalid 45- `F` - failure: the test was run but its results are invalid
@@ -155,3 +74,46 @@ To run all tests annotated with `@group WIP`:
155```bash 74```bash
156$ vendor/bin/phpunit --group WIP tests/ 75$ vendor/bin/phpunit --group WIP tests/
157``` 76```
77
78### Running tests inside Docker containers
79
80Test Dockerfiles are located under `tests/docker/<distribution>/Dockerfile`,
81and can be used to build Docker images to run Shaarli test suites under common
82Linux environments.
83
84Dockerfiles are provided for the following environments:
85
86- `alpine36` - [Alpine 3.6](https://www.alpinelinux.org/downloads/)
87- `debian8` - [Debian 8 Jessie](https://www.debian.org/DebianJessie) (oldstable)
88- `debian9` - [Debian 9 Stretch](https://wiki.debian.org/DebianStretch) (stable)
89- `ubuntu16` - [Ubuntu 16.04 Xenial Xerus](http://releases.ubuntu.com/16.04/) (LTS)
90
91What's behind the curtains:
92
93- each image provides:
94 - a base Linux OS
95 - Shaarli PHP dependencies (OS packages)
96 - test PHP dependencies (OS packages)
97 - Composer
98- the local workspace is mapped to the container's `/shaarli/` directory,
99- the files are rsync'd so tests are run using a standard Linux user account
100 (running tests as `root` would bypass permission checks and may hide issues)
101- the tests are run inside the container.
102
103To run tests inside a Docker container:
104
105```bash
106# build the Debian 9 Docker image for unit tests
107$ cd /path/to/shaarli
108$ cd tests/docker/debian9
109$ docker build -t shaarli-test:debian9 .
110
111# install/update 3rd-party test dependencies
112$ composer install --prefer-dist
113
114# run tests using the freshly built image
115$ docker run -v $PWD:/shaarli shaarli-test:debian9 docker_test
116
117# run the full test campaign
118$ docker run -v $PWD:/shaarli shaarli-test:debian9 docker_all_tests
119```