=== What are you doing here? ===
[?] What are lnline tests?
[!] That's an simple test case that is done directly at the runtime(certainly must be only in dev environment). Test data is parsed from docblock
=== The goal ===
Except expensive unit tests, you can also test in very simple way without running any daemon or even console application.
You should only use docblock sections and add class testing to your autoloader or use testable trait.
$inlineTester = Testing\InlineTesting::getInstance(/* false to avoid testing, for ex. in prod environment */);
$inlineTester->testClass("Foo"); // this will test all methods from the class where are docblock @assert sections found
$inlineTester->testFunction("myFunc"); // this will test the function if any docblock entry there
In order to use Testable trait you have to add it o_O:
class Foo {
use Testing\Traits\Testable;
/**
* This method will be tested
* Note: the inline test will pass, but if not it will trigger an informative error
*
* @param int $foo
* @param int $bar
* @param array $things
* @return int
*
* @assert 2 and "2" and [1, 2, 3] equals 7
*/
private /* or protected even public */ function myMethod($foo, $bar, array $things = []){
return (int) $foo + (int) $bar + count($things);
}
private /* or public, does not matter */ function onAfterDestruct(){
// that is your destructor from now, because __destruct() is preserved by the Testable trait
// now you do not have to call testClass method each time you wanna test your classes
}
}
|