diff --git a/src/Concerns/Testable.php b/src/Concerns/Testable.php index b9000ce8..4075caf4 100644 --- a/src/Concerns/Testable.php +++ b/src/Concerns/Testable.php @@ -290,7 +290,7 @@ trait Testable return $arguments; } - if (in_array($testParameterTypes[0], [Closure::class, 'callable'])) { + if (isset($testParameterTypes[0]) && in_array($testParameterTypes[0], [Closure::class, 'callable'])) { return $arguments; } diff --git a/src/Support/Reflection.php b/src/Support/Reflection.php index 395a517e..68581b85 100644 --- a/src/Support/Reflection.php +++ b/src/Support/Reflection.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace Pest\Support; use Closure; +use InvalidArgumentException; use Pest\Exceptions\ShouldNotHappen; use Pest\TestSuite; use ReflectionClass; @@ -66,9 +67,17 @@ final class Reflection { $test = TestSuite::getInstance()->test; - return $test instanceof \PHPUnit\Framework\TestCase - ? Closure::fromCallable($callable)->bindTo($test)(...$test->providedData()) - : self::bindCallable($callable); + if (! $test instanceof \PHPUnit\Framework\TestCase) { + return self::bindCallable($callable); + } + + foreach ($test->providedData() as $value) { + if ($value instanceof Closure) { + throw new InvalidArgumentException('Bound datasets are not supported while doing high order testing.'); + } + } + + return Closure::fromCallable($callable)->bindTo($test)(...$test->providedData()); } /** diff --git a/tests/Features/DatasetsTests.php b/tests/Features/DatasetsTests.php index f6030926..7d209c40 100644 --- a/tests/Features/DatasetsTests.php +++ b/tests/Features/DatasetsTests.php @@ -361,3 +361,23 @@ it('can correctly resolve a bound dataset that returns an array but wants to be ]); todo('forbids to define tests in Datasets dirs and Datasets.php files'); + +dataset('greeting-string', [ + 'formal' => 'Evening', + 'informal' => 'yo', +]); + +it('may be used with high order') + ->with('greeting-string') + ->expect(fn (string $greeting) => $greeting) + ->throwsNoExceptions(); + +dataset('greeting-bound', [ + 'formal' => fn () => 'Evening', + 'informal' => fn () => 'yo', +]); + +it('may be used with high order even when bound') + ->with('greeting-bound') + ->expect(fn (string $greeting) => $greeting) + ->throws(InvalidArgumentException::class);