勉強日記

チラ裏

【PHPUnit】dataProviderを複数指定すると直和集合になる

<?php

namespace Tests\Feature;

use Tests\TestCase;

class ExampleTest extends TestCase
{
    /**
     * @test
     * @dataProvider dataProvider
     * @dataProvider dataProvider2
     */
    public function sample(int $num)
    {
        echo $num . PHP_EOL;
        $this->assertTrue(true);
    }

    public function dataProvider(): array
    {
        return [
            [
                1
            ],
            [
                2
            ],
            [
                3
            ],
        ];
    }

    public function dataProvider2(): array
    {
        return [
            [
                4
            ],
            [
                5
            ],
            [
                6
            ],
        ];
    }
}
bash-4.4# ./vendor/bin/phpunit -- tests/Feature/
PHPUnit 8.3.4 by Sebastian Bergmann and contributors.

.1
.2
.3
.4
.5
.                                                              6 / 6 (100%)6


Time: 1.22 seconds, Memory: 10.00 MB

OK (6 tests, 6 assertions)