This commit is contained in:
Fabio Ivona
2023-03-13 17:38:52 +01:00
parent 88e576c3a3
commit 1bd9c9e60d
2 changed files with 59 additions and 16 deletions

View File

@ -228,7 +228,23 @@ trait Testable
$this->__description = self::$__latestDescription = $this->dataName() ? $method->description.' with '.$this->dataName() : $method->description;
$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;
}
@ -236,9 +252,6 @@ trait Testable
return $arguments;
}
$underlyingTest = Reflection::getFunctionVariable($this->__test, 'closure');
$testParameterTypes = array_values(Reflection::getFunctionArguments($underlyingTest));
if (in_array($testParameterTypes[0], [\Closure::class, 'callable'])) {
return $arguments;
}

View File

@ -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) {