Skip to content

Commit

Permalink
Better error message when data provider is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Sep 24, 2024
1 parent ba61e62 commit eeb994d
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/Metadata/Api/DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ public function providedData(string $className, string $methodName): ?array
if (!is_array($value)) {
throw new InvalidDataProviderException(
sprintf(
'Data set %s is invalid',
'Data set %s is invalid, expected array but got %s',
is_int($key) ? '#' . $key : '"' . $key . '"',
get_debug_type($value)
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Data Provider Method Finished for PHPUnit\TestFixture\Event\InvalidDataProviderW
- PHPUnit\TestFixture\Event\InvalidDataProviderWithOneTestPassingTest::provider
Test Triggered PHPUnit Error (PHPUnit\TestFixture\Event\InvalidDataProviderWithOneTestPassingTest::testOne)
The data provider specified for PHPUnit\TestFixture\Event\InvalidDataProviderWithOneTestPassingTest::testOne is invalid
Data set #0 is invalid
Data set #0 is invalid, expected array but got int
Test Suite Loaded (1 test)
Test Runner Started
Test Suite Sorted
Expand Down
2 changes: 1 addition & 1 deletion tests/end-to-end/event/invalid-data-provider.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Data Provider Method Finished for PHPUnit\TestFixture\Event\InvalidDataProviderT
- PHPUnit\TestFixture\Event\InvalidDataProviderTest::provider
Test Triggered PHPUnit Error (PHPUnit\TestFixture\Event\InvalidDataProviderTest::testOne)
The data provider specified for PHPUnit\TestFixture\Event\InvalidDataProviderTest::testOne is invalid
Data set #0 is invalid
Data set #0 is invalid, expected array but got int
Test Runner Triggered Warning (No tests found in class "PHPUnit\TestFixture\Event\InvalidDataProviderTest".)
Test Suite Loaded (0 tests)
Test Runner Started
Expand Down
4 changes: 2 additions & 2 deletions tests/end-to-end/regression/2137-filter.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ There were 2 PHPUnit errors:

1) PHPUnit\TestFixture\Issue2137Test::testBrandService
The data provider specified for PHPUnit\TestFixture\Issue2137Test::testBrandService is invalid
Data set #0 is invalid
Data set #0 is invalid, expected array but got stdClass

%s:%d

2) PHPUnit\TestFixture\Issue2137Test::testSomethingElseInvalid
The data provider specified for PHPUnit\TestFixture\Issue2137Test::testSomethingElseInvalid is invalid
Data set #0 is invalid
Data set #0 is invalid, expected array but got stdClass

%s:%d

Expand Down
4 changes: 2 additions & 2 deletions tests/end-to-end/regression/2137-no_filter.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ There were 2 PHPUnit errors:

1) PHPUnit\TestFixture\Issue2137Test::testBrandService
The data provider specified for PHPUnit\TestFixture\Issue2137Test::testBrandService is invalid
Data set #0 is invalid
Data set #0 is invalid, expected array but got stdClass

%s:%d

2) PHPUnit\TestFixture\Issue2137Test::testSomethingElseInvalid
The data provider specified for PHPUnit\TestFixture\Issue2137Test::testSomethingElseInvalid is invalid
Data set #0 is invalid
Data set #0 is invalid, expected array but got stdClass

%s:%d

Expand Down

0 comments on commit eeb994d

Please sign in to comment.