Skip to content

Commit e17e0ed

Browse files
trashercedric-anne
andcommitted
Fix tests documentation (#168)
* Fix tests documentation * Update source/sourcecode.rst --------- Co-authored-by: Cédric Anne <[email protected]>
1 parent 3145830 commit e17e0ed

File tree

1 file changed

+15
-48
lines changed

1 file changed

+15
-48
lines changed

source/sourcecode.rst

Lines changed: 15 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -262,31 +262,10 @@ Unit testing (and functional testing)
262262

263263
A note for the purists... In GLPI, there are both unit and functional tests; without real distinction ;-)
264264

265-
We use `PHPUnit <https://phpunit.de>`_ for tests.
266-
`atoum`'s documentation in available at: http://docs.atoum.org
265+
We use `PHPUnit <https://phpunit.de>`_ for PHP tests.
267266

268267
For JavaScript tests, GLPI uses the Jest testing framework.
269-
It's documentation can be found at: https://devdocs.io/jest/.
270-
271-
.. warning::
272-
273-
With `atoum`, test class **must** refer to an existing class of the project!
274-
This means that your test class must have the same name and relative namespace as an existing class.]
275-
276-
Tests isolation
277-
^^^^^^^^^^^^^^^
278-
279-
PHP tests must be run in an isolated environment. By default, `atoum` use a concurrent mode; that launches tests in a multi-threaded environment. While it is possible to bypass this; this should not be done See http://docs.atoum.org/en/latest/engine.html.
280-
281-
For technical reasons (mainly because of the huge session usage), GLPI PHP unit tests are actually limited to one only thread while running the whole suite; but while developing, the behavior should only be changed if this is really needed.
282-
283-
For JavaScript tests, Jest is able to run multiple tests in parallel as long as they are in different *spec* files since they don't interact with database data or a server.
284-
This behavior is the default.
285-
286-
Type hitting
287-
^^^^^^^^^^^^
288-
289-
Unlike PHPUnit, `atoum` is very strict on type hitting. This really makes sense; but often in GLPI types are not what we should expect (for example, we often get a string and not an integer from counting methods).
268+
Its documentation can be found at: https://devdocs.io/jest/.
290269

291270
Database
292271
^^^^^^^^
@@ -323,44 +302,32 @@ When you use a property that has not been declared, you will have errors that ma
323302
Launch tests
324303
^^^^^^^^^^^^
325304
326-
You can install `atoum` from composer (just run ``composer install`` from GLPI directory) or even system wide.
305+
All required :ref:`third party libraries are installed at once <3rd_party_libs>`, including testing framework.
327306
328-
There are two directories for tests:
307+
There are several directories for tests:
329308

330-
* ``tests/units`` for main core tests;
331-
* ``tests/api`` for API tests.
309+
* ``phpunit/functionnal`` for main core unit/functional tests;
310+
* ``phpunit/LDAP`` - requires a LDAP server;
311+
* ``phpunit/web`` - requires a web server;
312+
* ``phpunit/imap`` - requires mail server;
332313

333-
You can choose to run tests on a whole directory, or on any file (+ on a specific method). You have to specify a bootstrap file each time:
314+
You can choose to run tests on a whole directory, or on any file (+ on a specific method). Refer to PHPUnit documentation for more information.
334315

335316
.. code-block:: bash
336317
337-
$ atoum -bf tests/bootstrap.php -mcn 1 -d tests/units/
318+
$ ./vendor/bin/phpunit phpunit/functional/
338319
[...]
339-
$ atoum -bf tests/bootstrap.php -f tests/units/Html.php
320+
$ ./vendor/bin/phpunit phpunit/functional/ComputerTest.php
340321
[...]
341-
$ atoum -bf tests/bootstrap.php -f tests/functionnal/Ticket.php -m tests\units\Ticket::testTechAcls
322+
$ $ ./vendor/bin/phpunit phpunit/functional/ComputerTest.php --filter testSomething
342323
343324
344-
If you want to run the API tests suite, you need to run a development server:
325+
If you want to run the web tests suite, you need to run a web server, and give tests its URL when running. Here is an example using PHP native webserver:
345326

346327
.. code-block:: bash
347328
348-
php -S localhost:8088 tests/router.php &>/dev/null &
349-
350-
351-
Running `atoum` without any arguments will show you the possible options. Most important are:
352-
353-
* ``-bf`` to set bootstrap file,
354-
* ``-d`` to run tests located in a whole directory,
355-
* ``-f`` to run tests on a standalone file,
356-
* ``-m`` to run tests on a specific method (-f must also be defined),
357-
* ``--debug`` to get extra informations when something goes wrong,
358-
* ``-mcn`` limit number of concurrent runs. This is unfortunately mandatory running the whole test suite right now :/,
359-
* ``-ncc`` do not generate code coverage,
360-
* ``--php`` to change PHP executable to use,
361-
* ``-l`` loop mode.
362-
363-
Note that if you do not use the `-ncc` switch; coverage will be generated in the `tests/code-coverage/` directory.
329+
$ php -S localhost:8088 tests/router.php &>/dev/null &
330+
$ GLPI_URI=http://localhost:8088 ./vendor/bin/phpunit phpunit/web/
364331
365332
To run the JavaScript unit tests, simply run `npm test` in a terminal from the root of the GLPI folder.
366333
Currently, there is only a single "project" set up for Jest so this command will run all tests.

0 commit comments

Comments
 (0)