PHPackages                             inventor96/fatfree-test-manager - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. inventor96/fatfree-test-manager

ActiveLibrary[Testing &amp; Quality](/categories/testing)

inventor96/fatfree-test-manager
===============================

A lightweight class to run and report the results from unit tests using the Fat-Free Framework Test class.

v0.3.0(5y ago)239MITPHP

Since Mar 10Pushed 5y ago1 watchersCompare

[ Source](https://github.com/inventor96/fatfree-test-manager)[ Packagist](https://packagist.org/packages/inventor96/fatfree-test-manager)[ Docs](https://github.com/inventor96/fatfree-test-manager)[ RSS](/packages/inventor96-fatfree-test-manager/feed)WikiDiscussions main Synced yesterday

READMEChangelog (3)Dependencies (1)Versions (4)Used By (0)

Fat-Free 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](https://fatfreeframework.com/3.7/test).

Installation
------------

[](#installation)

```
composer require --dev inventor96/fatfree-test-manager

```

Usage
-----

[](#usage)

The goal of this tool is to be as simple and lightweight as possible.

### Overview

[](#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`

[](#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:

```
class MyTestBase extends TestBase {
	public function __construct(\Test &$test_instance) {
		parent::__construct($test_instance, [get_class()]);
	}
}
```

### Running code before/after test classes and methods

[](#running-code-beforeafter-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.

MethodCalled 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

[](#multiple-folders)

If you have more than one folder with tests, you can create an instance of the [Fat-Free Framework `Test` class](https://fatfreeframework.com/3.7/test) 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

[](#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
---------------

[](#general-example)

`example_dir/ExampleTest.php`:

```
