Skip to content

"Empty data set provided by data provider" #251

@staabm

Description

@staabm

Starting with PHPUnit 10 a dataprovider is not allowed to provide a empty array.

<?php

use PHPUnit\Framework\Attributes\DataProvider;

class BarTest extends PHPUnit\Framework\TestCase
{
    /**
     * @dataProvider provideData
     */
    #[DataProvider("provideData")]
    public function testBar() {
        self::assertTrue(true);
    }

    static public function provideData(): iterable {
        return [];
    }
}

real world example in phpstan-doctrine


PHPUnit 9 skips and warns

➜  phpunit git:(9.6) ✗ php phpunit BarTest.php
PHPUnit 9.6.29-15-g3ee3d102e by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.27
Configuration: /Users/staabm/workspace/phpunit/phpunit.xml

S                                                                   1 / 1 (100%)

Time: 00:00.002, Memory: 6.00 MB

There was 1 skipped test:

1) BarTest::testBar
Test for BarTest::testBar skipped by data provider
PHPUnit\Framework\SkippedTestError: <no message>
/Users/staabm/workspace/phpunit/src/Util/Annotation/DocBlock.php:285
/Users/staabm/workspace/phpunit/src/Util/Test.php:329
/Users/staabm/workspace/phpunit/src/Framework/TestBuilder.php:72
/Users/staabm/workspace/phpunit/src/Framework/TestSuite.php:891
/Users/staabm/workspace/phpunit/src/Framework/TestSuite.php:232
/Users/staabm/workspace/phpunit/src/Runner/BaseTestRunner.php:133
/Users/staabm/workspace/phpunit/src/TextUI/Command.php:121
/Users/staabm/workspace/phpunit/src/TextUI/Command.php:99

/Users/staabm/workspace/phpunit/src/Framework/Assert.php:2895
/Users/staabm/workspace/phpunit/src/Framework/SkippedTestCase.php:66
/Users/staabm/workspace/phpunit/src/Framework/TestCase.php:1223
/Users/staabm/workspace/phpunit/src/Framework/TestResult.php:729
/Users/staabm/workspace/phpunit/src/Framework/TestCase.php:973
/Users/staabm/workspace/phpunit/src/Framework/TestSuite.php:685
/Users/staabm/workspace/phpunit/src/Framework/TestSuite.php:685
/Users/staabm/workspace/phpunit/src/TextUI/TestRunner.php:651
/Users/staabm/workspace/phpunit/src/TextUI/Command.php:146
/Users/staabm/workspace/phpunit/src/TextUI/Command.php:99

OK, but incomplete, skipped, or risky tests!
Tests: 1, Assertions: 0, Skipped: 1.

PHPUnit 10 errors

➜  phpunit git:(10.5) ✗ php phpunit BarTest.php
PHPUnit 10.5.58-15-gc66b7d664 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.27
Configuration: /Users/staabm/workspace/phpunit/phpunit.xml

There was 1 PHPUnit error:

1) BarTest::testBar
The data provider specified for BarTest::testBar is invalid
Empty data set provided by data provider
/Users/staabm/workspace/phpunit/src/Metadata/Api/DataProvider.php:76
/Users/staabm/workspace/phpunit/src/Framework/TestBuilder.php:44
/Users/staabm/workspace/phpunit/src/Framework/TestSuite.php:511
/Users/staabm/workspace/phpunit/src/Framework/TestSuite.php:139
/Users/staabm/workspace/phpunit/src/TextUI/Configuration/TestSuiteBuilder.php:122
/Users/staabm/workspace/phpunit/src/TextUI/Configuration/TestSuiteBuilder.php:58
/Users/staabm/workspace/phpunit/src/TextUI/Application.php:394
/Users/staabm/workspace/phpunit/src/TextUI/Application.php:114

/Users/staabm/workspace/phpunit/BarTest.php:11

--

There was 1 PHPUnit test runner warning:

1) No tests found in class "BarTest".

No tests executed!

PHPUnit11,12,13 errors

➜  phpunit git:(11.5) ✗ php phpunit BarTest.php
PHPUnit 11.5.42-27-g32e5fd8bc by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.27
Configuration: /Users/staabm/workspace/phpunit/phpunit.xml

There was 1 PHPUnit error:

1) BarTest::testBar
The data provider specified for BarTest::testBar is invalid
Empty data set provided by data provider
/Users/staabm/workspace/phpunit/src/Metadata/Api/DataProvider.php:75
/Users/staabm/workspace/phpunit/src/Framework/TestBuilder.php:47
/Users/staabm/workspace/phpunit/src/Framework/TestSuite.php:508
/Users/staabm/workspace/phpunit/src/Framework/TestSuite.php:109
/Users/staabm/workspace/phpunit/src/TextUI/Configuration/TestSuiteBuilder.php:121
/Users/staabm/workspace/phpunit/src/TextUI/Configuration/TestSuiteBuilder.php:58
/Users/staabm/workspace/phpunit/src/TextUI/Application.php:412
/Users/staabm/workspace/phpunit/src/TextUI/Application.php:182

/Users/staabm/workspace/phpunit/BarTest.php:11

--

There was 1 PHPUnit test runner warning:

1) No tests found in class "BarTest".

No tests executed!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions