Unit tests

This chapter describes:

1 Introduction

To be sure that all parts of Gentics Portal.Node PHP work successfully, we use unit tests. The goal of unit testing is to isolate each part of the software and show that the individual parts are correct.

For this purposes we use PHPUnit.

Installation instructions are here.

2 Tests

All tests are stored in the folder tests/. This folder also contains all environment settings.

Unit tests must use a separate database (from production system), because during execution they clean all database tables.

Tests configuration is placed in the file tests/config/main.php

Before running the tests you should apply database migrations by using the console tool yiic, which is in tests/ folder. It has a separate configuration file tests/config/console.php (check database connection settings).

Unit tests itself can be found in the folder tests/unit/. For every portal module exists a separate folder.

2.1 Run tests

After setting up the database and all configuration files you can run tests via shell


cd <portal>/tests/
phpunit unit/

If all tests are successful, you will see an output like this


PHPUnit 3.6.10 by Sebastian Bergmann.

Configuration read from /var/www/gPortal/tests/phpunit.xml

...............................................................  63 / 150 ( 42%)
............................................................... 126 / 150 ( 84%)
........................

Time: 18 seconds, Memory: 26.50Mb

OK (150 tests, 256 assertions)