mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
wip
This commit is contained in:
@ -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];
|
||||
}
|
||||
|
||||
|
||||
@ -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 () {
|
||||
[
|
||||
'foo',
|
||||
function () {
|
||||
return 'bar';
|
||||
}], // This should be passed as a closure because we've passed multiple arguments
|
||||
},
|
||||
], // 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 () {
|
||||
[
|
||||
function () {
|
||||
return 'foo';
|
||||
}, 'bar'], // This should be passed as a closure because we've passed multiple arguments
|
||||
}, '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) {
|
||||
|
||||
Reference in New Issue
Block a user