PHP code example of inventor96 / fatfree-test-manager

1. Go to this page and download the library: Download inventor96/fatfree-test-manager library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

inventor96 / fatfree-test-manager example snippets


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



use inventor96\F3TestManager\TestBase;

class ExampleTest extends TestBase {
	private $pre_class_called = 0;
	private $post_class_called = 0;
	private $pre_test_called = 0;
	private $post_test_called = 0;

	public function preClass() {
		$this->pre_class_called++;
	}

	public function postClass() {
		$this->post_class_called++;

		echo "preClass() called: {$this->pre_class_called}".PHP_EOL;
		echo "postClass() called: {$this->post_class_called}".PHP_EOL;
		echo "preTest() called: {$this->pre_test_called}".PHP_EOL;
		echo "postTest() called: {$this->post_test_called}".PHP_EOL;
	}

	public function preTest() {
		$this->pre_test_called++;
	}

	public function postTest() {
		$this->post_test_called++;
	}

	private function testThisShouldNeverGetCalled() {
		// private methods should never get called by the TestManager
		$this->expect(false, 'This is not the method you are looking for...');
	}

	public function testPassExample() {
		$this->expect(true, 'the message for a passing test');
	}

	public function testFailExample() {
		$this->expect(false, 'the message for a failed test');
	}

	public function testPassAndFailExample() {
		$this->expect(true);
		$this->expect(false);
	}

	public function testWithException() {
		throw new Exception("This is the message for an exception");
	}
}



use inventor96\F3TestManager\TestManager;

.".PHP_EOL;
$test1 = new Test();
TestManager::runTests(__DIR__, $test1);
TestManager::reportTests($test1, false);

echo PHP_EOL."Running tests using one call.".PHP_EOL;
TestManager::runAndReportTests(__DIR__);