@@ -169,69 +169,67 @@ private function dataProvidedByMethods(string $testClassName, ReflectionMethod $
169169 throw InvalidDataProviderException::forException ($ e , $ providerLabel );
170170 }
171171
172- foreach ($ data as $ key => $ value ) {
173- if (!is_int ($ key ) && !is_string ($ key )) {
174- Event \Facade::emitter ()->dataProviderMethodFinished (
175- $ testMethodValueObject ,
176- ...$ methodsCalled ,
177- );
178-
179- throw new InvalidDataProviderException (
180- sprintf (
181- 'The key must be an integer or a string, %s given ' ,
182- get_debug_type ($ key ),
183- ),
184- );
185- }
186-
187- if (!is_array ($ value )) {
188- Event \Facade::emitter ()->dataProviderMethodFinished (
189- $ testMethodValueObject ,
190- ...$ methodsCalled ,
191- );
192-
193- throw new InvalidDataProviderException (
194- sprintf (
195- 'Data set %s provided by %s is invalid, expected array but got %s ' ,
172+ try {
173+ foreach ($ data as $ key => $ value ) {
174+ if (!is_int ($ key ) && !is_string ($ key )) {
175+ throw new InvalidDataProviderException (
176+ sprintf (
177+ 'The key must be an integer or a string, %s given ' ,
178+ get_debug_type ($ key ),
179+ ),
180+ );
181+ }
182+
183+ if (!is_array ($ value )) {
184+ throw new InvalidDataProviderException (
185+ sprintf (
186+ 'Data set %s provided by %s is invalid, expected array but got %s ' ,
187+ $ this ->formatKey ($ key ),
188+ $ providerLabel ,
189+ get_debug_type ($ value ),
190+ ),
191+ );
192+ }
193+
194+ if ($ validateArgumentCount && $ testMethodNumberOfParameters < count ($ value )) {
195+ $ this ->triggerWarningForArgumentCount (
196+ $ testMethod ,
196197 $ this ->formatKey ($ key ),
197198 $ providerLabel ,
198- get_debug_type ($ value ),
199- ),
200- );
201- }
202-
203- if ($ validateArgumentCount && $ testMethodNumberOfParameters < count ($ value )) {
204- $ this ->triggerWarningForArgumentCount (
205- $ testMethod ,
206- $ this ->formatKey ($ key ),
207- $ providerLabel ,
208- count ($ value ),
209- $ testMethodNumberOfParameters ,
210- );
211- }
212-
213- if (is_int ($ key )) {
214- $ result [] = new ProvidedData ($ providerLabel , $ value );
215-
216- continue ;
217- }
218-
219- if (array_key_exists ($ key , $ result )) {
220- Event \Facade::emitter ()->dataProviderMethodFinished (
221- $ testMethodValueObject ,
222- ...$ methodsCalled ,
223- );
224-
225- throw new InvalidDataProviderException (
226- sprintf (
227- 'The key "%s" has already been defined by provider %s ' ,
228- $ key ,
229- $ result [$ key ]->label (),
230- ),
231- );
199+ count ($ value ),
200+ $ testMethodNumberOfParameters ,
201+ );
202+ }
203+
204+ if (is_int ($ key )) {
205+ $ result [] = new ProvidedData ($ providerLabel , $ value );
206+
207+ continue ;
208+ }
209+
210+ if (array_key_exists ($ key , $ result )) {
211+ throw new InvalidDataProviderException (
212+ sprintf (
213+ 'The key "%s" has already been defined by provider %s ' ,
214+ $ key ,
215+ $ result [$ key ]->label (),
216+ ),
217+ );
218+ }
219+
220+ $ result [$ key ] = new ProvidedData ($ providerLabel , $ value );
232221 }
222+ } catch (Throwable $ e ) {
223+ Event \Facade::emitter ()->dataProviderMethodFinished (
224+ $ testMethodValueObject ,
225+ ...$ methodsCalled ,
226+ );
233227
234- $ result [$ key ] = new ProvidedData ($ providerLabel , $ value );
228+ throw new InvalidDataProviderException (
229+ $ e ->getMessage (),
230+ $ e ->getCode (),
231+ $ e ,
232+ );
235233 }
236234 }
237235
0 commit comments