mirror of
https://github.com/pestphp/pest.git
synced 2026-03-13 03:07:22 +01:00
Merge pull request #685 from fabio-ivona/fix-multiple-dataset-test-case-access
Fix multiple dataset test case access
This commit is contained in:
@ -228,7 +228,22 @@ trait Testable
|
|||||||
|
|
||||||
$this->__description = self::$__latestDescription = $this->dataName() ? $method->description.' with '.$this->dataName() : $method->description;
|
$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) {
|
if (count($arguments) !== 1) {
|
||||||
|
foreach ($arguments as $argumentIndex => $argumentValue) {
|
||||||
|
if (! $argumentValue instanceof Closure) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (in_array($testParameterTypes[$argumentIndex], [\Closure::class, 'callable', 'mixed'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$arguments[$argumentIndex] = $this->__callClosure($argumentValue, []);
|
||||||
|
}
|
||||||
|
|
||||||
return $arguments;
|
return $arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,9 +251,6 @@ trait Testable
|
|||||||
return $arguments;
|
return $arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
$underlyingTest = Reflection::getFunctionVariable($this->__test, 'closure');
|
|
||||||
$testParameterTypes = array_values(Reflection::getFunctionArguments($underlyingTest));
|
|
||||||
|
|
||||||
if (in_array($testParameterTypes[0], [\Closure::class, 'callable'])) {
|
if (in_array($testParameterTypes[0], [\Closure::class, 'callable'])) {
|
||||||
return $arguments;
|
return $arguments;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
##teamcity[testSuiteStarted name='Tests/tests/Failure' locationHint='file://tests/.tests/Failure.php' flowId='1234']
|
##teamcity[testSuiteStarted name='Tests/tests/Failure' locationHint='file://tests/.tests/Failure.php' flowId='1234']
|
||||||
##teamcity[testStarted name='it can fail with comparison' locationHint='pest_qn://tests/.tests/Failure.php::it can fail with comparison' flowId='1234']
|
##teamcity[testStarted name='it can fail with comparison' locationHint='pest_qn://tests/.tests/Failure.php::it can fail with comparison' flowId='1234']
|
||||||
##teamcity[testFailed name='it can fail with comparison' message='Failed asserting that true matches expected false.' details='at src/Mixins/Expectation.php:342|nat src/Support/ExpectationPipeline.php:75|nat src/Support/ExpectationPipeline.php:79|nat src/Expectation.php:300|nat tests/.tests/Failure.php:6|nat src/Factories/TestCaseMethodFactory.php:100|nat src/Concerns/Testable.php:262|nat src/Support/ExceptionTrace.php:28|nat src/Concerns/Testable.php:262|nat src/Concerns/Testable.php:217|nat src/Kernel.php:90' type='comparisonFailure' actual='true' expected='false' flowId='1234']
|
##teamcity[testFailed name='it can fail with comparison' message='Failed asserting that true matches expected false.' details='at src/Mixins/Expectation.php:342|nat src/Support/ExpectationPipeline.php:75|nat src/Support/ExpectationPipeline.php:79|nat src/Expectation.php:300|nat tests/.tests/Failure.php:6|nat src/Factories/TestCaseMethodFactory.php:100|nat src/Concerns/Testable.php:274|nat src/Support/ExceptionTrace.php:28|nat src/Concerns/Testable.php:274|nat src/Concerns/Testable.php:217|nat src/Kernel.php:90' type='comparisonFailure' actual='true' expected='false' flowId='1234']
|
||||||
##teamcity[testFinished name='it can fail with comparison' duration='100000' flowId='1234']
|
##teamcity[testFinished name='it can fail with comparison' duration='100000' flowId='1234']
|
||||||
##teamcity[testStarted name='it can be ignored because of no assertions' locationHint='pest_qn://tests/.tests/Failure.php::it can be ignored because of no assertions' flowId='1234']
|
##teamcity[testStarted name='it can be ignored because of no assertions' locationHint='pest_qn://tests/.tests/Failure.php::it can be ignored because of no assertions' flowId='1234']
|
||||||
##teamcity[testIgnored name='it can be ignored because of no assertions' message='This test did not perform any assertions' details='' flowId='1234']
|
##teamcity[testIgnored name='it can be ignored because of no assertions' message='This test did not perform any assertions' details='' flowId='1234']
|
||||||
@ -9,7 +9,7 @@
|
|||||||
##teamcity[testIgnored name='it can be ignored because it is skipped' message='This test was ignored.' details='' flowId='1234']
|
##teamcity[testIgnored name='it can be ignored because it is skipped' message='This test was ignored.' details='' flowId='1234']
|
||||||
##teamcity[testFinished name='it can be ignored because it is skipped' duration='100000' flowId='1234']
|
##teamcity[testFinished name='it can be ignored because it is skipped' duration='100000' flowId='1234']
|
||||||
##teamcity[testStarted name='it can fail' locationHint='pest_qn://tests/.tests/Failure.php::it can fail' flowId='1234']
|
##teamcity[testStarted name='it can fail' locationHint='pest_qn://tests/.tests/Failure.php::it can fail' flowId='1234']
|
||||||
##teamcity[testFailed name='it can fail' message='oh noo' details='at tests/.tests/Failure.php:18|nat src/Factories/TestCaseMethodFactory.php:100|nat src/Concerns/Testable.php:262|nat src/Support/ExceptionTrace.php:28|nat src/Concerns/Testable.php:262|nat src/Concerns/Testable.php:217|nat src/Kernel.php:90' flowId='1234']
|
##teamcity[testFailed name='it can fail' message='oh noo' details='at tests/.tests/Failure.php:18|nat src/Factories/TestCaseMethodFactory.php:100|nat src/Concerns/Testable.php:274|nat src/Support/ExceptionTrace.php:28|nat src/Concerns/Testable.php:274|nat src/Concerns/Testable.php:217|nat src/Kernel.php:90' flowId='1234']
|
||||||
##teamcity[testFinished name='it can fail' duration='100000' flowId='1234']
|
##teamcity[testFinished name='it can fail' duration='100000' flowId='1234']
|
||||||
##teamcity[testStarted name='it is not done yet' locationHint='pest_qn://tests/.tests/Failure.php::it is not done yet' flowId='1234']
|
##teamcity[testStarted name='it is not done yet' locationHint='pest_qn://tests/.tests/Failure.php::it is not done yet' flowId='1234']
|
||||||
##teamcity[testIgnored name='it is not done yet' message='This test was ignored.' details='' flowId='1234']
|
##teamcity[testIgnored name='it is not done yet' message='This test was ignored.' details='' flowId='1234']
|
||||||
|
|||||||
@ -111,6 +111,10 @@
|
|||||||
✓ eager registered wrapped datasets with Generator functions display description with data set "james"
|
✓ eager registered wrapped datasets with Generator functions display description with data set "james"
|
||||||
✓ it can resolve a dataset after the test case is available with (Closure Object (…)) #1
|
✓ it can resolve a dataset after the test case is available with (Closure Object (…)) #1
|
||||||
✓ it can resolve a dataset after the test case is available with (Closure Object (…)) #2
|
✓ it can resolve a dataset after the test case is available with (Closure Object (…)) #2
|
||||||
|
✓ it can resolve a dataset after the test case is available with multiple datasets with (Closure Object (…)) / (Closure Object (…)) #1
|
||||||
|
✓ it can resolve a dataset after the test case is available with multiple datasets with (Closure Object (…)) / (Closure Object (…)) #2
|
||||||
|
✓ it can resolve a dataset after the test case is available with multiple datasets with (Closure Object (…)) / (Closure Object (…)) #3
|
||||||
|
✓ it can resolve a dataset after the test case is available with multiple datasets with (Closure Object (…)) / (Closure Object (…)) #4
|
||||||
✓ it can resolve a dataset after the test case is available with shared yield sets with (Closure Object (…)) #1
|
✓ it can resolve a dataset after the test case is available with shared yield sets with (Closure Object (…)) #1
|
||||||
✓ it can resolve a dataset after the test case is available with shared yield sets with (Closure Object (…)) #2
|
✓ it can resolve a dataset after the test case is available with shared yield sets with (Closure Object (…)) #2
|
||||||
✓ it can resolve a dataset after the test case is available with shared array sets with (Closure Object (…)) #1
|
✓ it can resolve a dataset after the test case is available with shared array sets with (Closure Object (…)) #1
|
||||||
@ -929,4 +933,4 @@
|
|||||||
PASS Tests\Visual\Version
|
PASS Tests\Visual\Version
|
||||||
✓ visual snapshot of help command output
|
✓ visual snapshot of help command output
|
||||||
|
|
||||||
Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 18 skipped, 634 passed (1567 assertions)
|
Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 18 skipped, 638 passed (1571 assertions)
|
||||||
@ -262,9 +262,33 @@ it('can resolve a dataset after the test case is available', function ($result)
|
|||||||
function () {
|
function () {
|
||||||
return $this->foo;
|
return $this->foo;
|
||||||
},
|
},
|
||||||
[function () {
|
[
|
||||||
|
function () {
|
||||||
return $this->foo;
|
return $this->foo;
|
||||||
}],
|
},
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
it('can resolve a dataset after the test case is available with multiple datasets', function (string $result, string $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) {
|
it('can resolve a dataset after the test case is available with shared yield sets', function ($result) {
|
||||||
@ -279,18 +303,23 @@ it('resolves a potential bound dataset logically', function ($foo, $bar) {
|
|||||||
expect($foo)->toBe('foo');
|
expect($foo)->toBe('foo');
|
||||||
expect($bar())->toBe('bar');
|
expect($bar())->toBe('bar');
|
||||||
})->with([
|
})->with([
|
||||||
['foo', function () {
|
[
|
||||||
|
'foo',
|
||||||
|
function () {
|
||||||
return 'bar';
|
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) {
|
it('resolves a potential bound dataset logically even when the closure comes first', function ($foo, $bar) {
|
||||||
expect($foo())->toBe('foo');
|
expect($foo())->toBe('foo');
|
||||||
expect($bar)->toBe('bar');
|
expect($bar)->toBe('bar');
|
||||||
})->with([
|
})->with([
|
||||||
[function () {
|
[
|
||||||
|
function () {
|
||||||
return 'foo';
|
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) {
|
it('will not resolve a closure if it is type hinted as a closure', function (Closure $data) {
|
||||||
|
|||||||
@ -15,6 +15,6 @@ $run = function () {
|
|||||||
};
|
};
|
||||||
|
|
||||||
test('parallel', function () use ($run) {
|
test('parallel', function () use ($run) {
|
||||||
expect($run())->toContain('Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 15 skipped, 626 passed (1555 assertions)')
|
expect($run())->toContain('Tests: 2 deprecated, 3 warnings, 4 incomplete, 1 notice, 4 todos, 15 skipped, 630 passed (1559 assertions)')
|
||||||
->toContain('Parallel: 3 processes');
|
->toContain('Parallel: 3 processes');
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user