From eeb994dd877f942eba33b7923a896c54adc5b318 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 24 Sep 2024 10:18:12 +0200 Subject: [PATCH] Better error message when data provider is invalid --- src/Metadata/Api/DataProvider.php | 3 ++- .../event/invalid-data-provider-with-passing-test.phpt | 2 +- tests/end-to-end/event/invalid-data-provider.phpt | 2 +- tests/end-to-end/regression/2137-filter.phpt | 4 ++-- tests/end-to-end/regression/2137-no_filter.phpt | 4 ++-- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Metadata/Api/DataProvider.php b/src/Metadata/Api/DataProvider.php index 3adcb1a2adc..33406986b60 100644 --- a/src/Metadata/Api/DataProvider.php +++ b/src/Metadata/Api/DataProvider.php @@ -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) ), ); } diff --git a/tests/end-to-end/event/invalid-data-provider-with-passing-test.phpt b/tests/end-to-end/event/invalid-data-provider-with-passing-test.phpt index 75222994940..4e6b19e3cae 100644 --- a/tests/end-to-end/event/invalid-data-provider-with-passing-test.phpt +++ b/tests/end-to-end/event/invalid-data-provider-with-passing-test.phpt @@ -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 diff --git a/tests/end-to-end/event/invalid-data-provider.phpt b/tests/end-to-end/event/invalid-data-provider.phpt index 955b2bfdb4a..761b7236eed 100644 --- a/tests/end-to-end/event/invalid-data-provider.phpt +++ b/tests/end-to-end/event/invalid-data-provider.phpt @@ -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 diff --git a/tests/end-to-end/regression/2137-filter.phpt b/tests/end-to-end/regression/2137-filter.phpt index dfcc749d296..7b56bcda1c4 100644 --- a/tests/end-to-end/regression/2137-filter.phpt +++ b/tests/end-to-end/regression/2137-filter.phpt @@ -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 diff --git a/tests/end-to-end/regression/2137-no_filter.phpt b/tests/end-to-end/regression/2137-no_filter.phpt index 38632c11b9a..2f68ffbbfaf 100644 --- a/tests/end-to-end/regression/2137-no_filter.phpt +++ b/tests/end-to-end/regression/2137-no_filter.phpt @@ -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