diff options
Diffstat (limited to 'doc')
-rw-r--r-- | doc/md/Server-configuration.md | 2 | ||||
-rw-r--r-- | doc/md/Server-security.md | 8 | ||||
-rw-r--r-- | doc/md/Unit-tests-Docker.md | 56 | ||||
-rw-r--r-- | doc/md/Unit-tests.md | 158 |
4 files changed, 65 insertions, 159 deletions
diff --git a/doc/md/Server-configuration.md b/doc/md/Server-configuration.md index bd293c37..f9ea2ed2 100644 --- a/doc/md/Server-configuration.md +++ b/doc/md/Server-configuration.md | |||
@@ -187,7 +187,7 @@ http { | |||
187 | ``` | 187 | ``` |
188 | 188 | ||
189 | ```ini | 189 | ```ini |
190 | # /etc/php5/fpm/php.ini | 190 | # /etc/php/<PHP_VERSION>/fpm/php.ini |
191 | 191 | ||
192 | [...] | 192 | [...] |
193 | post_max_size = 10M | 193 | post_max_size = 10M |
diff --git a/doc/md/Server-security.md b/doc/md/Server-security.md index 700084e2..ea1b637d 100644 --- a/doc/md/Server-security.md +++ b/doc/md/Server-security.md | |||
@@ -1,10 +1,10 @@ | |||
1 | ## php.ini | 1 | ## php.ini |
2 | PHP settings are defined in: | 2 | PHP settings are defined in: |
3 | 3 | ||
4 | - a main configuration file, usually found under `/etc/php5/php.ini`; some distributions provide different configuration environments, e.g. | 4 | - a main configuration file, usually found under `/etc/php/$php_version/php.ini`; some distributions provide different configuration environments, e.g. |
5 | - `/etc/php5/php.ini` - used when running console scripts | 5 | - `/etc/php/$php_version/cli/php.ini` - used when running console scripts |
6 | - `/etc/php5/apache2/php.ini` - used when a client requests PHP resources from Apache | 6 | - `/etc/php/$php_version/apache2/php.ini` - used when a client requests PHP resources from Apache |
7 | - `/etc/php5/php-fpm.conf` - used when PHP requests are proxied to PHP-FPM | 7 | - `/etc/php/$php_version/php-fpm.conf` - used when PHP requests are proxied to PHP-FPM |
8 | - additional configuration files/entries, depending on the installed/enabled extensions: | 8 | - additional configuration files/entries, depending on the installed/enabled extensions: |
9 | - `/etc/php/conf.d/xdebug.ini` | 9 | - `/etc/php/conf.d/xdebug.ini` |
10 | 10 | ||
diff --git a/doc/md/Unit-tests-Docker.md b/doc/md/Unit-tests-Docker.md deleted file mode 100644 index 59bd5b45..00000000 --- a/doc/md/Unit-tests-Docker.md +++ /dev/null | |||
@@ -1,56 +0,0 @@ | |||
1 | ## Running tests inside Docker containers | ||
2 | |||
3 | Read first: | ||
4 | |||
5 | - [Docker 101](docker/docker-101.md) | ||
6 | - [Docker resources](docker/resources.md) | ||
7 | - [Unit tests](Unit-tests.md) | ||
8 | |||
9 | ### Docker test images | ||
10 | |||
11 | Test Dockerfiles are located under `tests/docker/<distribution>/Dockerfile`, | ||
12 | and can be used to build Docker images to run Shaarli test suites under common | ||
13 | Linux environments. | ||
14 | |||
15 | Dockerfiles are provided for the following environments: | ||
16 | |||
17 | - `alpine36` - [Alpine 3.6](https://www.alpinelinux.org/downloads/) | ||
18 | - `debian8` - [Debian 8 Jessie](https://www.debian.org/DebianJessie) (oldstable) | ||
19 | - `debian9` - [Debian 9 Stretch](https://wiki.debian.org/DebianStretch) (stable) | ||
20 | - `ubuntu16` - [Ubuntu 16.04 Xenial Xerus](http://releases.ubuntu.com/16.04/) (LTS) | ||
21 | |||
22 | What's behind the curtains: | ||
23 | |||
24 | - each image provides: | ||
25 | - a base Linux OS | ||
26 | - Shaarli PHP dependencies (OS packages) | ||
27 | - test PHP dependencies (OS packages) | ||
28 | - Composer | ||
29 | - the local workspace is mapped to the container's `/shaarli/` directory, | ||
30 | - the files are rsync'd so tests are run using a standard Linux user account | ||
31 | (running tests as `root` would bypass permission checks and may hide issues) | ||
32 | - the tests are run inside the container. | ||
33 | |||
34 | ### Building test images | ||
35 | |||
36 | ```bash | ||
37 | # build the Debian 9 Docker image | ||
38 | $ cd /path/to/shaarli | ||
39 | $ cd tests/docker/debian9 | ||
40 | $ docker build -t shaarli-test:debian9 . | ||
41 | ``` | ||
42 | |||
43 | ### Running tests | ||
44 | |||
45 | ```bash | ||
46 | $ cd /path/to/shaarli | ||
47 | |||
48 | # install/update 3rd-party test dependencies | ||
49 | $ composer install --prefer-dist | ||
50 | |||
51 | # run tests using the freshly built image | ||
52 | $ docker run -v $PWD:/shaarli shaarli-test:debian9 docker_test | ||
53 | |||
54 | # run the full test campaign | ||
55 | $ docker run -v $PWD:/shaarli shaarli-test:debian9 docker_all_tests | ||
56 | ``` | ||
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 | 1 | The 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 | ||
3 | The 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 | ||
7 | You can either use: | 7 | You 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 | ||
32 | See http://xdebug.org/docs/install | 22 | Xdebug must be installed and enable for PHPUnit to generate coverage reports. See http://xdebug.org/docs/install. |
33 | 23 | ||
34 | For Debian-based distros: | ||
35 | ```bash | ||
36 | $ aptitude install php5-xdebug | ||
37 | ``` | ||
38 | For 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 | ||
43 | Then add the following line to `/etc/php/php.ini`: | 32 | Then add the following line to `/etc/php/<PHP_VERSION>/cli/php.ini`: |
33 | |||
44 | ```ini | 34 | ```ini |
45 | zend_extension=xdebug.so | 35 | zend_extension=xdebug.so |
46 | ``` | 36 | ``` |
47 | 37 | ||
48 | #### Run unit tests | 38 | ## Run unit tests |
49 | |||
50 | Successful test suite: | ||
51 | ```bash | ||
52 | $ make test | ||
53 | |||
54 | ------- | ||
55 | PHPUNIT | ||
56 | ------- | ||
57 | PHPUnit 4.6.9 by Sebastian Bergmann and contributors. | ||
58 | |||
59 | Configuration read from /home/virtualtam/public_html/shaarli/phpunit.xml | ||
60 | |||
61 | .................................... | ||
62 | |||
63 | Time: 759 ms, Memory: 8.25Mb | ||
64 | |||
65 | OK (36 tests, 65 assertions) | ||
66 | ``` | ||
67 | |||
68 | Test suite with failures and errors: | ||
69 | ```bash | ||
70 | $ make test | ||
71 | ------- | ||
72 | PHPUNIT | ||
73 | ------- | ||
74 | PHPUnit 4.6.9 by Sebastian Bergmann and contributors. | ||
75 | |||
76 | Configuration read from /home/virtualtam/public_html/shaarli/phpunit.xml | ||
77 | |||
78 | E..FF............................... | ||
79 | |||
80 | Time: 802 ms, Memory: 8.25Mb | ||
81 | |||
82 | There was 1 error: | ||
83 | |||
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 | ||
87 | |||
88 | /home/virtualtam/public_html/shaarli/application/LinkDB.php:58 | ||
89 | /home/virtualtam/public_html/shaarli/tests/LinkDBTest.php:79 | ||
90 | |||
91 | -- | ||
92 | |||
93 | There were 2 failures: | ||
94 | |||
95 | 1) LinkDBTest::testCheckDBNew | ||
96 | Failed 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 | |||
105 | 2) LinkDBTest::testCheckDBLoad | ||
106 | Failed 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 | |||
115 | FAILURES! | ||
116 | Tests: 36, Assertions: 63, Errors: 1, Failures: 2. | ||
117 | ``` | ||
118 | |||
119 | #### Test results and coverage | ||
120 | 39 | ||
121 | By default, PHPUnit will run all suitable tests found under the `tests` directory. | 40 | Run `make test` and ensure tests return `OK`. If tests return failures, refer to PHPUnit messages and fix your code/tests accordingly. |
122 | 41 | ||
123 | Each test has 3 possible outcomes: | 42 | By 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 | |||
80 | Test Dockerfiles are located under `tests/docker/<distribution>/Dockerfile`, | ||
81 | and can be used to build Docker images to run Shaarli test suites under common | ||
82 | Linux environments. | ||
83 | |||
84 | Dockerfiles 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 | |||
91 | What'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 | |||
103 | To 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 | ``` | ||