Skip to content

Cannot run_single_phpunit_test when test uses @dataProvider #36

@adamtomat

Description

@adamtomat

I have a test which is using a data provider. It runs as expected when running the whole file, however the individual test filter does not account for data providers.


Example Test:

use Tests\TestCase;

class ExampleTest extends TestCase
{
    function exampleDataProvider()
    {
        return [
            ['foo'],
        ];
    }

    /**
     * @test
     * @dataProvider exampleDataProvider
     */
    function example_test($foo)
    {
        $this->assertSame('foo', $foo);
    }
}

Output when running run_phpunit_test:

cd /Users/adamtomat/Sites/<repo> && /Users/adamtomat/Sites/<repo>/vendor/phpunit/phpunit/phpunit /Users/adamtomat/Sites/<repo>/tests/Feature/ExampleTest.php

OK (1 test, 1 assertion)

Output when running run_single_phpunit_test:

cd /Users/adamtomat/Sites/<repo> && /Users/adamtomat/Sites/<repo>/vendor/phpunit/phpunit/phpunit /Users/adamtomat/Sites/<repo>/tests/Feature/ExampleTest.php --filter '/::example_test$/'

No tests executed!

After a little searching around, it looks like the filter needs to account for tests with data providers, which explains why it doesn't work:

https://stackoverflow.com/questions/12193606/cannot-run-single-test-with-data-provider-in-phpunit

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions