Skip to content

feature-ninja/testing-matrix

Repository files navigation

Testing Matrix

Latest Version on Packagist Tests Total Downloads

Easily test multiple scenarios by creating a testing matrix

Installation

You can install the package via composer:

composer require feature-ninja/testing-matrix

Usage

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
    {
        // ...
    }
}

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.