aboutsummaryrefslogtreecommitdiff
blob: 54db823b4ac4e82e526fe7f464b7291c7d09ba01 (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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
Running Tests
=============

Prerequisites
=============

PHPUnit
-------

phpBB unit tests use the PHPUnit framework (see http://www.phpunit.de for more
information). Version 3.5 or higher is required to run the tests. PHPUnit can
be installed via Composer together with other development dependencies as
follows.

    $ cd phpBB
    $ php ../composer.phar install --dev
    $ cd ..

PHP extensions
--------------

Unit tests use several PHP extensions that board code does not use. Currently
the following PHP extensions must be installed and enabled to run unit tests:

- ctype (also a PHPUnit dependency)
- dom (PHPUnit dependency)
- json (also a phpBB dependency)

Some of the functionality in phpBB and/or the test suite uses additional
PHP extensions. If these extensions are not loaded, respective tests
will be skipped:

- apcu (APCu cache driver - native API, php7+)
- apcu_bc, apcu (APCu cache driver - APC API, php7+)
- bz2 (compress tests)
- mysqli, pdo_mysql (MySQLi database driver)
- pcntl (flock class)
- pdo (any database tests)
- pgsql, pdo_pgsql (PostgreSQL database driver)
- redis (https://github.com/nicolasff/phpredis, Redis cache driver)
- simplexml (any database tests)
- sqlite, pdo_sqlite (SQLite database driver, requires SQLite 2.x support
  in pdo_sqlite)
- zlib (compress tests)

Database Tests
--------------

By default all tests requiring a database connection will use sqlite. If you
do not have sqlite installed the tests will be skipped. If you wish to run the
tests on a different database you have to create a test_config.php file within
your tests directory following the same format as phpBB's config.php. Testing
makes use of a separate database defined in this config file and before running
the tests each time this database is deleted. An example for mysqli can be
found below. More information on configuration options can be found on the
wiki (see below).

    <?php
    $dbms = 'phpbb\db\driver\mysqli';
    $dbhost = 'localhost';
    $dbport = '';
    $dbname = 'database';
    $dbuser = 'user';
    $dbpasswd = 'password';

It is possible to have multiple test_config.php files, for example if you
are testing on multiple databases. You can specify which test_config.php file
to use in the environment as follows:

    $ PHPBB_TEST_CONFIG=tests/test_config.php phpunit

Alternatively you can specify parameters in the environment, so e.g. the
following will run PHPUnit with the same parameters as in the shown
test_config.php file:

    $ PHPBB_TEST_DBMS='mysqli' PHPBB_TEST_DBHOST='localhost' \
      PHPBB_TEST_DBNAME='database' PHPBB_TEST_DBUSER='user' \
      PHPBB_TEST_DBPASSWD='password' phpunit

Special Database Cases
----------------------
In order to run tests on some of the databases that we support, it will be
necessary to provide a custom DSN string in test_config.php. This is only
needed for MSSQL 2000+ (PHP module) and MSSQL via ODBC. The variable must be
named `$custom_dsn`.

Example MSSQL:

    $custom_dsn = "Driver={SQL Server Native Client 10.0};Server=$dbhost;Database=$dbname";

The other fields in test_config.php should be filled out as you would normally
to connect to that database in phpBB.

Additionally, you will need to be running the DbUnit fork from
https://github.com/phpbb/dbunit/tree/phpbb.

Redis
-----

In order to run tests for the Redis cache driver, at least one of Redis host
or port must be specified in test configuration. This can be done via
test_config.php as follows:

    <?php
    $phpbb_redis_host = 'localhost';
    $phpbb_redis_port = 6379;

Or via environment variables as follows:

    $ PHPBB_TEST_REDIS_HOST=localhost PHPBB_TEST_REDIS_PORT=6379 phpunit

Memcached
---------

In order to run tests for the memcached cache driver, at least one of memcached
host or port must be specified in the test configuration. This can be done via
test_config.php as follows:

    <?php
    $phpbb_memcached_host = 'localhost';
    $phpbb_memcached_port = '11211';

Or via environment variables as follows:

    $ PHPBB_TEST_MEMCACHED_HOST=localhost PHPBB_TEST_MEMCACHED_PORT=11211 phpunit

Running
=======

Once the prerequisites are installed, run the tests from the project root
directory (above phpBB):

    $ phpBB/vendor/bin/phpunit

To generate an xml log file, run:

    $ phpBB/vendor/bin/phpunit --log-junit tests/tmp/log/log.xml

If you are getting a memory exhausted error after running a few tests, you can try running:

    $ phpBB/vendor/bin/phpunit -d memory_limit=2048M

Slow tests
--------------

Certain tests, such as the DNS tests tend to be slow.
Thus these tests are in the `slow` group, which is excluded by default. You can
enable slow tests by copying the phpunit.xml.all file to phpunit.xml. If you
only want the slow tests, run:

    $ phpBB/vendor/bin/phpunit --group slow

If you want all tests, run:

    $ phpBB/vendor/bin/phpunit --group __nogroup__,functional,slow


Functional tests
================

Functional tests test software the way a user would. They simulate a user
browsing the website, but they do these steps in an automated way.
phpBB allows you to write such tests.

Running
-------

Running the tests requires your phpBB3 repository to be accessible through a
local web server. You will need to supply the URL to the webserver in
the 'tests/test_config.php' file. This is as simple as defining the
'$phpbb_functional_url' variable, which contains the URL for the directory containing
the board. Make sure you include the trailing slash. Note that without extensive
changes to the test framework, you cannot use a board outside of the repository
on which to run tests.

    $phpbb_functional_url = 'http://localhost/phpBB3/';

Functional tests are automatically run, if '$phpbb_functional_url' is configured.
If you only want the functional tests, run:

    $ phpBB/vendor/bin/phpunit --group functional

This will change your board's config.php file, but it makes a backup at
config_dev.php, so you can restore it after the test run is complete.

UI tests
========

UI tests are functional tests that also support running JavaScript in a
headless browser. These should be used when functionality that is only
executed using JS needs to be tested. They require a running
[PhantomJS WebDriver instance](http://phantomjs.org/). The executable can
either be downloaded from [PhantomJS](http://phantomjs.org/download.html)
or alternatively be installed with npm:

    $ npm install -g phantomjs-prebuilt

You might have to run the command as superuser / administrator on some
systems. Afterwards, a new WebDriver instance can be started via command
line:

    $ phantomjs --webdriver=127.0.0.1:8910

Port 8910 is the default port that will be used by UI tests to connect
to the WebDriver instance.

More Information
================

Further information is available on phpbb wiki:
http://wiki.phpbb.com/Automated_Tests