-
Notifications
You must be signed in to change notification settings - Fork 36
Open
Description
I have a question regarding the need to duplicate the types specified in @return in a data provider. Given the following test:
<?php declare(strict_types=1);
namespace MyNamespace;
use PHPUnit\Framework\TestCase;
class SomeTest extends TestCase
{
/**
* @return array<string,array{data:array<string,string>}>
*/
public static function getData(): array
{
return [
'some data' => [
'data' => [
'foo' => 'bar',
'bar' => 'foo',
],
],
];
}
/**
* @dataProvider getData
*/
public function testSomething(array $data): void
{
foreach ($data as $key => $value) {
// do some assertions
}
}
}If I run psalm with an errorLevel set to 1 on this code I get the following error:
ERROR: MixedAssignment - tests/SomeTest.php:28:35 - Unable to determine the type that $value is being assigned to (see https://psalm.dev/032)
foreach ($data as $key => $value) {
I thought psalm might get this information from the @return docblock in the data provider. Do I need to duplicate the type for array $data as $param array< ... > $data on the testSomething method, or am I missing something?
Metadata
Metadata
Assignees
Labels
No labels