mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
feat: clarfies that high order testing does not support bound datasets
This commit is contained in:
@ -290,7 +290,7 @@ trait Testable
|
|||||||
return $arguments;
|
return $arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array($testParameterTypes[0], [Closure::class, 'callable'])) {
|
if (isset($testParameterTypes[0]) && in_array($testParameterTypes[0], [Closure::class, 'callable'])) {
|
||||||
return $arguments;
|
return $arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace Pest\Support;
|
namespace Pest\Support;
|
||||||
|
|
||||||
use Closure;
|
use Closure;
|
||||||
|
use InvalidArgumentException;
|
||||||
use Pest\Exceptions\ShouldNotHappen;
|
use Pest\Exceptions\ShouldNotHappen;
|
||||||
use Pest\TestSuite;
|
use Pest\TestSuite;
|
||||||
use ReflectionClass;
|
use ReflectionClass;
|
||||||
@ -66,9 +67,17 @@ final class Reflection
|
|||||||
{
|
{
|
||||||
$test = TestSuite::getInstance()->test;
|
$test = TestSuite::getInstance()->test;
|
||||||
|
|
||||||
return $test instanceof \PHPUnit\Framework\TestCase
|
if (! $test instanceof \PHPUnit\Framework\TestCase) {
|
||||||
? Closure::fromCallable($callable)->bindTo($test)(...$test->providedData())
|
return self::bindCallable($callable);
|
||||||
: 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());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -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');
|
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);
|
||||||
|
|||||||
Reference in New Issue
Block a user