summaryrefslogtreecommitdiff
path: root/doc/tests.markdown
blob: b2d954911ad0ab9e482ae51d60092bddfa1c369c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
Automated tests
===============

[PHPUnit](https://phpunit.de/) is used to run automated tests on Kanboard.

You can run tests across different databases (Sqlite, Mysql and Postgresql) to be sure that the result is the same everywhere.

Requirements
------------

- Linux/Unix machine
- PHP cli
- PHPUnit installed
- Mysql and Postgresql (optional)

Unit Tests
----------

### Test with Sqlite

Sqlite tests use a in-memory database, nothing is written on the file system.

The PHPUnit config file is `tests/units.sqlite.xml`.
From your Kanboard directory, run the command `phpunit -c tests/units.sqlite.xml`.

Example:

```bash
phpunit -c tests/units.sqlite.xml

PHPUnit 5.0.0 by Sebastian Bergmann and contributors.

...............................................................  63 / 649 (  9%)
............................................................... 126 / 649 ( 19%)
............................................................... 189 / 649 ( 29%)
............................................................... 252 / 649 ( 38%)
............................................................... 315 / 649 ( 48%)
............................................................... 378 / 649 ( 58%)
............................................................... 441 / 649 ( 67%)
............................................................... 504 / 649 ( 77%)
............................................................... 567 / 649 ( 87%)
............................................................... 630 / 649 ( 97%)
...................                                             649 / 649 (100%)

Time: 1.22 minutes, Memory: 151.25Mb

OK (649 tests, 43595 assertions)
```

### Test with Mysql

You must have Mysql or MariaDb installed on localhost.

By default, those credentials are used:

- Hostname: **localhost**
- Username: **root**
- Password: none
- Database: **kanboard_unit_test**

For each execution the database is dropped and created again.

The PHPUnit config file is `tests/units.mysql.xml`.
From your Kanboard directory, run the command `phpunit -c tests/units.mysql.xml`.

### Test with Postgresql

You must have Postgresql installed on localhost.

By default, those credentials are used:

- Hostname: **localhost**
- Username: **postgres**
- Password: none
- Database: **kanboard_unit_test**

Be sure to allow the user `postgres` to create and drop databases.
The database is recreated for each execution.

The PHPUnit config file is `tests/units.postgres.xml`.
From your Kanboard directory, run the command `phpunit -c tests/units.postgres.xml`.

Integration Tests
-----------------

Actually only the API calls are tested.

Real HTTP calls are made with those tests.
So a local instance of Kanboard is necessary and must listen on `http://localhost:8000/`.

All data will be removed/altered by the test suite.
Moreover the script will reset and set a new API key.

1. Start a local instance of Kanboard `php -S 127.0.0.1:8000`
2. Run the test suite from another terminal

The same method as above is used to run tests across different databases:

- Sqlite: `phpunit -c tests/integration.sqlite.xml`
- Mysql: `phpunit -c tests/integration.mysql.xml`
- Postgresql: `phpunit -c tests/integration.postgres.xml`

Example:

```bash
phpunit -c tests/integration.sqlite.xml

PHPUnit 5.0.0 by Sebastian Bergmann and contributors.

...............................................................  63 / 135 ( 46%)
............................................................... 126 / 135 ( 93%)
.........                                                       135 / 135 (100%)

Time: 1.18 minutes, Memory: 14.75Mb

OK (135 tests, 526 assertions)
```

Continuous Integration with Travis-CI
-------------------------------------

After each commit pushed on the main repository, unit tests are executed across 5 different versions of PHP:

- PHP 7.0
- PHP 5.6
- PHP 5.5
- PHP 5.4
- PHP 5.3

Each version of PHP is tested against the 3 supported database: Sqlite, Mysql and Postgresql.

The Travis config file `.travis.yml` is located on the root directory of Kanboard.