feature-ninja/testing-matrix

通过创建测试矩阵轻松测试多个场景

0.1.1 2024-09-11 15:52 UTC

This package is auto-updated.

Last update: 2024-09-16 17:01:15 UTC


README

Latest Version on Packagist Tests Total Downloads

通过创建测试矩阵轻松测试多个场景

安装

您可以通过composer安装此包

composer require feature-ninja/testing-matrix

使用方法

从数组创建测试矩阵

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],
]);

在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

变更日志

请参阅 CHANGELOG 了解最近更改的详细信息。

安全漏洞

请参阅 我们的安全策略 了解如何报告安全漏洞。

鸣谢

许可

MIT许可(MIT)。请参阅 许可文件 获取更多信息。