Skip to content


XELOS integrates the popular testing framework Codeception to support the writing of different types of tests. Currently Unit Tests and Functional Tests are supported.

XELOS 7.1 supports tests only for the core functions - module specific tests are supported since XELOS 8.0. Core tests are being located in the /tests/ folder of the system, while module tests are saved in the respective module folder.


The namespacing for tests inside Modules should be as follow:

The following paths should map the corresponding namespaces:

namespace XELOS\Modules\Lists\Tests\Codeception\Unit\ListControllerTest

namespace XELOS\Modules\Lists\Tests\Codeception\Support\Helper\ListHelper

The namespacing in the global test directory (/server/xelos/tests) is analog to the module namespaces:

namespace XELOS\Tests\Codeception\Unit\SomeTest

namespace XELOS\Tests\Codeception\Support\Helper\SomeHelper

To uphold codeception standards, the codeception folder itself and the next folder should be lower case, and the folders after the codeception folders should be ucfirst():

[...]/tests/codeception/unit/Helper/Some/More[...] [...]/tests/codeception/support/Lib/Api[...]

The defined namespace in the codeception.yml files has to map the the defined "settings" folder in "path":

# codeception.yml in: /server/xelos
namespace: XELOS\Tests\Codeception\Support
 support: tests/codeception/support

otherwise the enabled modules will not be correctly resolved:

# unit.suite.dist.yml in: /server/xelos/tests/codeception
namespace: XELOS\Tests\Codeception\Support
    - XELOS\Tests\Codeception\Support\Module\XELOSBootstrapper

# The Codeception Autoloader will look for the XELOSBootstrapper file
# in the Module/ subfolder of the previously defined support path 

Running Test

Test can be run using php xf test all. To be able to run a test you must have a working XELOS installation. Furthermore, you need a config.tests.php configuration in your /system/config/ folder. This can be a copy of your config.custom.php file but should be linked to another database as running the tests will wipe the existing database. Make sure that the user and database exists before continuing.

To run tests locally you need composer dev modules installed. Run composer update.

During writing tests it might be helpful to run only a specific test to reduce the waiting time. This can be done by specifying the suite and test file name - e.g. php xf test unit core/xelosDatabaseTest.php or php xf test functional Core/basicFormCheckCest.php

Note: You can also run tests directly via Codeception, e.g. ./vendor/bin/codecept run functional Core/basicFormCheckCest.php. Please refer to the official Codeception docs for more information about syntax and features:

You can see the return of your test in the codeception/_output directory.

Tipps und Tricks

  1. Immer Cest-Klassen verwenden (da Cept Dateien Scripte sind, welches ein Scenario nutzen, womit man nur einen Kontext abbilden kann und eher an Nicht-Entwickler gerichtet ist)

  2. Erstellen von Funktionen in Cest-Klassen: public Funktionen werden immer als Testfunktionen ausgeführt, möchte man ein Funktion innerhalb der Klasse, als Helper und nicht als Test, muss man die Funktion entweder protected deklarieren oder wenn man sie public macht/braucht den Methodenname mit einem Unterstrich prefixen. Bsp: _myFunction.

  3. Use-Case und Codeception-Code einfach als Akzeptanztest zusammenklicken

  4. Testdurchläufe mit verschiedenen Daten: innerhalb der Cest-Klasse eine Method erstellen: (Access Modifier siehe Punkt 2.)

protected function myDataProvider(){
  return [
    ['start' => '2019-04-22', 'end' => '2019-04-27', 'airportId' => 1]

und diese per Annotation @dataProvider myDataProvider der zu nutzenden Testfunktion bekannt machen.

 * @param Endpoints $I
 * @param \Codeception\Example $myDataProvider
 * @dataProvider myDataProvider
public function comparePricesFromWebpageWithEndpoint(\XELOS\Tests\FunctionalTester $I, \Codeception\Example $myDataProvider)

        "method" => "list_available_products",
        "params" => [
            "startDate" => $myDataProvider['start'],
            "endDate" => $myDataProvider['end'],
            "airportId" => $myDataProvider['airportId'],
            "lang" => "de_DE"
        "id" => 1

    foreach ($this->prices as $price){
        $I->seeResponseContainsJson(['price' => $price]);


Writing Unit Tests

Please make yourself familiar with general CodeCeption tests by looking into existing tests or the official documentation as we are not able to cover the basics in this document:

A basic functional test will look like this:

class basicFormCheckCest {
    // Admin can Login
    public function tryFormBasicFunction(\XELOS\Tests\FunctionalTester $I) {
        // LOGIN
        $I->fillField('userid', 'admin');
        $I->fillField('password', 'admin');

        $page_url = '/systemadmin/dev/form';
        $I->wantToTest("Testing page {$page_url} < for errors");


It is possible to inject helper classes so you do not have to call them as static

class MyUnitTest extends \Codeception\Test\Unit {

    /** @var XFHelper $XFHelper */
    protected $XFHelper;

    public function _inject(XFHelper $XFHelper) {
        $this->XFHelper = $XFHelper;

    protected function _before() {


Mocking & Reflection Examples

How to reset the XF instance via reflection

// Available in \XELOS\Tests\Codeception\Support\Helper\XFHelper->resetXF()
$XF = XF::instance();
$XFReflection = new \ReflectionObject($XF);
$InitializedProperty = $XFReflection->getProperty('initialized');
$InitializedProperty->setValue($XF, false);

Example: Mocking the get_available_languages() function of the i18n object and replacing it in $XF

// Create the i18n mock object
$i18n = $this->make(new \XELOS\Framework\XF\Lib\i18n, [
    'get_available_languages' => function($with_captions = false, $show_only_active = true) {
        $result = ['DE_DE' => 'Deutsch', 'EN_GB' => 'English', 'ES_ES' => 'Español'];
        return ($with_captions) ? $result : array_keys($result);

// Inject the mocked i18n object via reflection
$lib = \XELOS\Framework\XF::instance()->lib;
// Call i18n once to initialize the private property in $lib
$reflection = new \ReflectionObject($lib);
$I18nProperty = $reflection->getProperty('i18n');
$I18nProperty->setValue($lib, $i18n);

Codeception Examples for module

Create Unit Test for Test:

php vendor/bin/codecept generate:test unit ListsController -c modules/lists/tests/codeception

Validate configuration:

php vendor/bin/codecept config:validate -c modules/lists/tests/codeception/

Run functional tests for a single module:

php vendor/bin/codecept run functional -c modules/lists/tests/codeception/