Download the PHP package inventor96/fatfree-test-manager without Composer
On this page you can find all versions of the php package inventor96/fatfree-test-manager. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download inventor96/fatfree-test-manager
More information about inventor96/fatfree-test-manager
Files in inventor96/fatfree-test-manager
Package fatfree-test-manager
Short Description A lightweight class to run and report the results from unit tests using the Fat-Free Framework Test class.
License MIT
Homepage https://github.com/inventor96/fatfree-test-manager
Informations about the package fatfree-test-manager
Fat-Free Test Manager
A lightweight class to run and report the results from unit tests using the Fat-Free Framework Test
class.
Installation
Usage
The goal of this tool is to be as simple and lightweight as possible.
Overview
The idea is that we'll scan one folder (non-recursively) for all files that end with Test.php
(e.g. MyAwesomeTest.php
). For each of the files found, we find the first class definition, instantiate that class, and then call all public methods in that class that start with test
(e.g. public function testIfThisWorks() { ... }
).
With this structure in place, simply call TestManager::runAndReportTests('directory/with/test/files');
.
Extending TestBase
The test classes must extend TestBase
, directly or indirectly. If indirectly (the test classes extend another class that extends TestBase
), the constructor of the class(es) in the middle will want to pass an array as the second parameter to the parent constructor of class names that includes their own. This will allow the report to include the correct class and method name of the testing method.
For example:
Running code before/after test classes and methods
If a test class (or a class it extends) has a method named preClass()
, preTest()
, postTest()
, or postClass()
; each method will be called at the respective time.
Method | Called Time |
---|---|
preClass() |
Immediately after the class is instantiated |
preTest() |
Before each test*() method in the class |
postTest() |
After each test*() method in the class |
postClass() |
After all tests in the class have been run, and postTest() has been called (if present) |
Multiple Folders
If you have more than one folder with tests, you can create an instance of the Fat-Free Framework Test
class and call TestManager::runTests('a/directory/with/tests', $your_instance_of_Test);
for each directory, then call TestManager::reportTests($your_instance_of_Test);
at the end.
Exit Codes
By default, runAndReportTests()
and reportTests()
will end the PHP process with an exit code of 1 if there were failed tests, or 0 if all were successful. To disable this behavior and allow the script to continue, set the last parameter to false
.
General Example
example_dir/ExampleTest.php
:
example_dir/test_runner.php
:
Running the tests would look like this: