1. Go to this page and download the library: Download rawsrc/exacodis 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/ */
rawsrc / exacodis example snippets
declare(strict_types=1);
// create new project
$pilot = new Pilot('Exacodis - A PHP minimalist test framework');
$pilot->injectStandardHelpers();
// manual test
$stats = $pilot->getStats();
unset($stats['milliseconds'], $stats['hms']);
// we encapsulate the result in a closure to use it for testing purpose
$pilot->run(
id: '007',
description: 'check the count',
test: fn() => $stats;
);
// then we lead our assertions
$pilot->assertIsArray();
$pilot->assertEqual([
'nb_runs' => 6,
'passed_runs' => 5,
'failed_runs' => 1,
'passed_runs_percent' => round(5/6*100, 2),
'failed_runs_percent' => 100-round(5/6*100, 2),
'nb_assertions' => 18,
'passed_assertions' => 17,
'failed_assertions' => 1,
'passed_assertions_percent' => round(17/18*100, 2),
'failed_assertions_percent' => 100-round(17/18*100, 2)
]);
public function runClassMethod(
int|string|null $id,
object|string $class,
string $description = '',
?string $method = null,
array $params = [],
)
$foo = new Foo();
$pilot->runClassMethod(
id: '008',
description: 'private method unit test using directly an instance of Foo',
class: $foo, // instance
method: 'abc',
);
$pilot->assertIsString();
$pilot->assertEqual('abc');
$pilot->runClassMethod(
id: '009',
description: 'private method unit test using string notation for the class Foo',
class: 'Foo', // class name
method: 'abc',
);
$pilot->assertIsString();
$pilot->assertEqual('abc');
$pilot->runClassMethod(
id: '010',
description: 'private method unit test using short string notation for the class Foo and the method abc',
class: 'Foo::abc', // short notation
);
$pilot->assertIsString();
$pilot->assertEqual('abc');
$pilot->runClassMethod(
id: '012',
description: 'private method unit test with two parameters',
class: 'Foo',
method: 'hij',
params: ['p' => 25, 'q' => 50] // or [25, 50]
);
$pilot->assertIsInt();
$pilot->assertEqual(250);
$pilot->runClassMethod(
id: '018',
description: 'private static method unit test',
class: 'Foo::tuv',
);
$pilot->assertIsString();
$pilot->assertEqual('tuv');
$pilot->run(
id: 'abc',
description: 'complex nested tests',
test: function() use ($pilot) {
// nested run
$pilot->run(
id: 'def',
description: 'nested run',
test: function() {
// ...
return $foo;
}
)
// careful: this applies to the (latest) run which is here 'def'
$pilot->assertIsArray();
return []; // a run MUST always return a value
}
);
// careful, if you continue the assertions here, by default they will apply to the
// (latest) run which is still 'def'; you must change the current runner to work with the previous one
$pilot->setCurrentRunnerTo('abc');
$pilot->assertIsArray(); // now it applies to the run 'abc'
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.