Documentation: Unit Tests

is a script whose only purpose is to use Unit Testing API in running as well as generating unit tests (unlike industry standard PHPUnit). All classes subject of unit testing must be located in src folder and their unit test equivalents will be located in tests folder and use Tests\Lucinda\Project\... namespaces in order to be autoloaded!


In order to run unit tests already included in project skeleton you will have to obey following requirements:

  1. have an SQL vendor installed (eg: MySQL) + PHP extension
  2. have an NoSQL vendor installed (eg: Redis) + PHP extension
  3. have SQL mock user created: test identified by me
  4. have SQL mock schema created: test, for whom above user has full rights
  5. have SQL tables created in above schema: , and .

In case you're using different vendors than MySQL and Redis, be aware that unit tests are configured in one or more XML files (depending on what it's tested) found in tests/mocks folder! Otherwise, please use SQL provided in Tutorial.

Running/Generating Unit Tests

To run unit tests on console go to your project root, open console and run:

php test.php

This will:

  1. loop through all classes in src folder
  2. loop through all classes in tests folder
  3. if a class in src folder has no equivalent in tests folder, it will be created according to following algorithm:
  4. if a class in src folder has equivalent in tests folder, but one of its public methods is not mirrored:
  5. loops through all classes in tests folder and:
  6. displays results collected in console

Writing Unit Tests

If you've developed a class in src folder (or developed a new method to an existing class) and ran , you will need to feed code to methods generated. Rules:

By default framework uses mock versions of stdout.xmlstdout.xml & stderr.xml as well as mock DAOs for database operations, but you can also use real mock DB on tests schema. In order to keep order for your project, it is advised to develop mocks in tests/mocks folder!

To learn more how to write unit tests, check Tutorial!