@@ -62,40 +62,10 @@ public function providedData(string $className, string $methodName): ?array
62
62
$ this ->triggerWarningForMixingOfDataProviderAndTestWith ($ testMethod );
63
63
}
64
64
65
- $ data = $ this ->dataProvidedByMethods ($ testMethod , $ dataProvider );
66
- } else {
67
- $ data = $ this ->dataProvidedByMetadata ($ testWith );
65
+ return $ this ->dataProvidedByMethods ($ testMethod , $ dataProvider );
68
66
}
69
67
70
- $ testMethodNumberOfParameters = $ testMethod ->getNumberOfParameters ();
71
- $ testMethodIsNonVariadic = !$ testMethod ->isVariadic ();
72
-
73
- foreach ($ data as $ key => $ providedData ) {
74
- $ value = $ providedData ->value ();
75
-
76
- if (!is_array ($ value )) {
77
- throw new InvalidDataProviderException (
78
- sprintf (
79
- 'Data set %s provided by %s is invalid, expected array but got %s ' ,
80
- $ this ->formatKey ($ key ),
81
- $ providedData ->label (),
82
- get_debug_type ($ value ),
83
- ),
84
- );
85
- }
86
-
87
- if ($ testMethodIsNonVariadic && $ testMethodNumberOfParameters < count ($ value )) {
88
- $ this ->triggerWarningForArgumentCount (
89
- $ testMethod ,
90
- $ this ->formatKey ($ key ),
91
- $ providedData ->label (),
92
- count ($ value ),
93
- $ testMethodNumberOfParameters ,
94
- );
95
- }
96
- }
97
-
98
- return $ data ;
68
+ return $ this ->dataProvidedByMetadata ($ testMethod , $ testWith );
99
69
}
100
70
101
71
/**
@@ -219,13 +189,15 @@ private function dataProvidedByMethods(ReflectionMethod $testMethod, MetadataCol
219
189
);
220
190
}
221
191
192
+ $ this ->validate ($ testMethod , $ result );
193
+
222
194
return $ result ;
223
195
}
224
196
225
197
/**
226
198
* @return array<ProvidedData>
227
199
*/
228
- private function dataProvidedByMetadata (MetadataCollection $ testWith ): array
200
+ private function dataProvidedByMetadata (ReflectionMethod $ testMethod , MetadataCollection $ testWith ): array
229
201
{
230
202
$ result = [];
231
203
@@ -253,9 +225,47 @@ private function dataProvidedByMetadata(MetadataCollection $testWith): array
253
225
}
254
226
}
255
227
228
+ $ this ->validate ($ testMethod , $ result );
229
+
256
230
return $ result ;
257
231
}
258
232
233
+ /**
234
+ * @param array<ProvidedData> $data
235
+ *
236
+ * @throws InvalidDataProviderException
237
+ */
238
+ private function validate (ReflectionMethod $ testMethod , array $ data ): void
239
+ {
240
+ $ testMethodNumberOfParameters = $ testMethod ->getNumberOfParameters ();
241
+ $ testMethodIsNonVariadic = !$ testMethod ->isVariadic ();
242
+
243
+ foreach ($ data as $ key => $ providedData ) {
244
+ $ value = $ providedData ->value ();
245
+
246
+ if (!is_array ($ value )) {
247
+ throw new InvalidDataProviderException (
248
+ sprintf (
249
+ 'Data set %s provided by %s is invalid, expected array but got %s ' ,
250
+ $ this ->formatKey ($ key ),
251
+ $ providedData ->label (),
252
+ get_debug_type ($ value ),
253
+ ),
254
+ );
255
+ }
256
+
257
+ if ($ testMethodIsNonVariadic && $ testMethodNumberOfParameters < count ($ value )) {
258
+ $ this ->triggerWarningForArgumentCount (
259
+ $ testMethod ,
260
+ $ this ->formatKey ($ key ),
261
+ $ providedData ->label (),
262
+ count ($ value ),
263
+ $ testMethodNumberOfParameters ,
264
+ );
265
+ }
266
+ }
267
+ }
268
+
259
269
/**
260
270
* @param int|non-empty-string $key
261
271
*
0 commit comments