Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error message when data provider is invalid #5963

Closed
staabm opened this issue Sep 24, 2024 · 1 comment · Fixed by #5964
Closed

Better error message when data provider is invalid #5963

staabm opened this issue Sep 24, 2024 · 1 comment · Fixed by #5964
Labels
feature/data-provider Data Providers type/enhancement A new idea that should be implemented

Comments

@staabm
Copy link
Contributor

staabm commented Sep 24, 2024

running php phpunit repro.php

with repro.php

<?php

final class repro extends \PHPUnit\Framework\TestCase
{
    /**
     * @return iterable<string>
     */
    public static function dataFile(): iterable
    {
        yield __DIR__ . '/data/preg-match.php';
        yield __DIR__ . '/data/preg-match-all.php';
    }

    /**
     * @dataProvider dataFile
     */
    public function testFile(string $file): void
    {
        self::assertTrue(true);
    }
}

I get

$ php phpunit repro.php
PHPUnit 11.4-gba61e62d4 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.2.12
Configuration: C:\dvl\Workspace\phpunit\phpunit.xml

There was 1 PHPUnit error:

1) repro::testFile
The data provider specified for repro::testFile is invalid
Data set #0 is invalid
C:\dvl\Workspace\phpunit\src\Metadata\Api\DataProvider.php:80
C:\dvl\Workspace\phpunit\src\Framework\TestBuilder.php:43
C:\dvl\Workspace\phpunit\src\Framework\TestSuite.php:514
C:\dvl\Workspace\phpunit\src\Framework\TestSuite.php:109
C:\dvl\Workspace\phpunit\src\TextUI\Configuration\TestSuiteBuilder.php:121
C:\dvl\Workspace\phpunit\src\TextUI\Configuration\TestSuiteBuilder.php:58
C:\dvl\Workspace\phpunit\src\TextUI\Application.php:412
C:\dvl\Workspace\phpunit\src\TextUI\Application.php:180

C:\dvl\Workspace\phpunit\repro.php:19

--

There was 1 PHPUnit test runner warning:

1) No tests found in class "repro".

I think DX wise I would expect a more meaningful error then

Data set #0 is invalid

maybe something like

Data set #0 is invalid, expected X got Y.

@staabm staabm added the type/enhancement A new idea that should be implemented label Sep 24, 2024
@staabm
Copy link
Contributor Author

staabm commented Sep 24, 2024

I am on it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/data-provider Data Providers type/enhancement A new idea that should be implemented
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants