Easily test multiple scenarios by creating a testing matrix
You can install the package via composer:
composer require feature-ninja/testing-matrix
Create a testing matrix from an array:
use FeatureNinja\TestingMatrix\Matrix;
$matrix = Matrix::create([
'a' => [1, 2],
'b' => [3, 4],
]);
assert(iterator_to_array($matrix) === [
'a=1 b=3' => [1, 3],
'a=1 b=4' => [1, 4],
'a=2 b=3' => [2, 3],
'a=2 b=4' => [2, 4],
]);
Usage in PHPUnit:
use FeatureNinja\TestingMatrix\Matrix;
use PHPUnit\Framework\Attributes\DataProvider;use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
final class ExampleTest extends TestCase
{
public static function example_data_provider(): Generator
{
yield from Matrix::create([
'a' => [1, 2],
'b' => [3, 4],
]);
}
#[Test]
#[DataProvider('examples')]
public function example(int $a, int $b): void
{
// ...
}
}
composer test
Please see CHANGELOG for more information on what has changed recently.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.