You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using a dataProvider with named arguments, phpunit throws a deprecation warning and will not use the argument correctly
How to Reproduce
<?phpit('can use named arguments', function (
string$a = 'foo',
?string$b = null,
): void {
expect(true)->toBeTrue();
})->with([
'positional arguments' => ['foo', 'bar'],
'named argument' => ['b' => 'bar'],
]);
Running the above code produces a deprecation warning and error similar to the following:
DEPR Tests\Unit\Test
! it can use named arguments → Providing invalid named argument $b for method P\Tests\Unit\Test::it_can_use_named_arguments() is deprecated and will not be supported in PHPUnit 11.0. 0.02s
✓ it can use named arguments with dataset "positional arguments" 0.18s
Tests: 1 deprecated, 1 passed (2 assertions)
Duration: 0.63s
This should work according to the phpunit functionality, however the generated test class code doesn't include the parameters. Phpunit uses reflection to get the parameters from the function and therefore this functionality is not working.
For completeness sake, this is the generated code:
namespace P\Tests\Unit;
use Pest\Repositories\DatasetsRepository as __PestDatasets;
/**
* @testdox /var/www/html/tests/Unit/Test.php
*/
#[\AllowDynamicProperties]
final class Test extends \Tests\TestCase implements \Pest\Contracts\HasPrintableTestCaseName
{
use \Pest\Concerns\Testable, \Pest\Concerns\Expectable, \Pest\Arch\Concerns\Architectable;
private static $__filename = '/var/www/html/tests/Unit/Test.php';
/**
* @test
* @testdox it can use named arguments
* @dataProvider __pest_evaluable_it_can_use_named_arguments_dataset
*/
public function __pest_evaluable_it_can_use_named_arguments()
{
$test = \Pest\TestSuite::getInstance()->tests->get(self::$__filename)->getMethod($this->name())->getClosure($this);
return $this->__runTest(
$test,
...func_get_args(),
);
}
public static function __pest_evaluable_it_can_use_named_arguments_dataset()
{
return __PestDatasets::get(self::$__filename, '__pest_evaluable_it_can_use_named_arguments');
}
}
Sample Repository
No response
Pest Version
v2.36.0
PHP Version
8.4.2
Operation System
Linux
Notes
No response
The text was updated successfully, but these errors were encountered:
<?php
it('can use named arguments', function (
string $a,
?string $b = null,
): void {
expect(true)->toBeTrue();
})->with([
'positional arguments' => ['foo', 'bar'],
'named argument' => ['a' => 'bar'],
]);
Just to make sure, do you have problems with this version of the reproduction code as well?
I'm certain Pest only allows positional arguments, but if it allowed named arguments, the original reproduction code should still fail because you're providing an argument to $b, which is a nullable string.
Meanwhile $a, a non-nullable string, gets nothing.
The above code should not fail, if Pest allowed named arguments, because it's providing a value to $a and nothing to $b.
What Happened
When using a dataProvider with named arguments, phpunit throws a deprecation warning and will not use the argument correctly
How to Reproduce
Running the above code produces a deprecation warning and error similar to the following:
This should work according to the phpunit functionality, however the generated test class code doesn't include the parameters. Phpunit uses reflection to get the parameters from the function and therefore this functionality is not working.
For completeness sake, this is the generated code:
Sample Repository
No response
Pest Version
v2.36.0
PHP Version
8.4.2
Operation System
Linux
Notes
No response
The text was updated successfully, but these errors were encountered: