diff --git a/src/Concerns/Testable.php b/src/Concerns/Testable.php index f7075c28..8c55b055 100644 --- a/src/Concerns/Testable.php +++ b/src/Concerns/Testable.php @@ -228,17 +228,30 @@ trait Testable $this->__description = self::$__latestDescription = $this->dataName() ? $method->description.' with '.$this->dataName() : $method->description; - if (count($arguments) !== 1) { - return $arguments; - } - - if (! $arguments[0] instanceof Closure) { - return $arguments; - } $underlyingTest = Reflection::getFunctionVariable($this->__test, 'closure'); $testParameterTypes = array_values(Reflection::getFunctionArguments($underlyingTest)); + if (count($arguments) !== 1) { + foreach ($arguments as $argumentIndex => $argumentValue) { + if (!$argumentValue instanceof Closure) { + continue; + } + + if (in_array($testParameterTypes[$argumentIndex], [\Closure::class, 'callable'])) { + continue; + } + + $arguments[$argumentIndex] = $this->__callClosure($argumentValue, []); + } + + return $arguments; + } + + if (!$arguments[0] instanceof Closure) { + return $arguments; + } + if (in_array($testParameterTypes[0], [\Closure::class, 'callable'])) { return $arguments; } @@ -247,7 +260,7 @@ trait Testable if (count($testParameterTypes) === 1) { return [$boundDatasetResult]; } - if (! is_array($boundDatasetResult)) { + if (!is_array($boundDatasetResult)) { return [$boundDatasetResult]; } diff --git a/tests/Features/DatasetsTests.php b/tests/Features/DatasetsTests.php index aeb0ba82..56ea47b4 100644 --- a/tests/Features/DatasetsTests.php +++ b/tests/Features/DatasetsTests.php @@ -262,9 +262,34 @@ it('can resolve a dataset after the test case is available', function ($result) function () { return $this->foo; }, - [function () { + [ + function () { + return $this->foo; + }, + ], +]); + + +it('can resolve a dataset after the test case is available with multiple datasets', function ($result, $result2) { + expect($result)->toBe('bar'); +})->with([ + function () { return $this->foo; - }], + }, + [ + function () { + return $this->foo; + }, + ], +], [ + function () { + return $this->foo; + }, + [ + function () { + return $this->foo; + }, + ], ]); it('can resolve a dataset after the test case is available with shared yield sets', function ($result) { @@ -279,18 +304,23 @@ it('resolves a potential bound dataset logically', function ($foo, $bar) { expect($foo)->toBe('foo'); expect($bar())->toBe('bar'); })->with([ - ['foo', function () { - return 'bar'; - }], // This should be passed as a closure because we've passed multiple arguments + [ + 'foo', + function () { + return 'bar'; + }, + ], // This should be passed as a closure because we've passed multiple arguments ]); it('resolves a potential bound dataset logically even when the closure comes first', function ($foo, $bar) { expect($foo())->toBe('foo'); expect($bar)->toBe('bar'); })->with([ - [function () { - return 'foo'; - }, 'bar'], // This should be passed as a closure because we've passed multiple arguments + [ + function () { + return 'foo'; + }, 'bar', + ], // This should be passed as a closure because we've passed multiple arguments ]); it('will not resolve a closure if it is type hinted as a closure', function (Closure $data) {