Duplicate types for PHPUnit data providers
メンテナーはふだん 1 日以内に返信
評価
調査の方向性
Start by reading the PHPUnit plugin code that handles @dataProvider annotations and the associated tests; the issue does not name specific files or test entry points. Reproduce the reported MixedAssignment with Psalm at error level 1, then check whether the provider's documented return type reaches the test parameter. Done means the behavior is understood and the issue's question about whether the parameter type must be duplicated is answered; an open linked pull request already indicates work is underway.
索引モデルが issue の本文から書いたものです。
説明
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?
- 主要言語
- Gherkin
- スター
- 79
- フォーク
- 38
- 平均マージ
- 6時間 52分
- マージ済み PR(30日)
- 28
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
psalm/psalm-plugin-phpunit のほかの issue
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
psalm/psalm-plugin-phpunit#222 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
psalm/psalm-plugin-phpunit#220 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
psalm/psalm-plugin-phpunit#219 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
psalm/psalm-plugin-phpunit#216 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 3/5 1〜2日 初心者へのやさしさ 57/100
psalm/psalm-plugin-phpunit#223 ·
メンテナーはふだん 1 日以内に返信
psalm/psalm-plugin-phpunit の issue をすべて見る
似ている issue
-
area: test kind: bug preview-effort: small priority: low
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
-
ai-driven-fuzzing bug claude Minor
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1〜3時間 初心者へのやさしさ 85/100
hibernate/hibernate-reactive#4485 ·
メンテナーはふだん 1 日以内に返信
-
auto-generated hub missing-coverage team/hub
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
camunda/api-test-generator#770 ·
メンテナーはふだん 1 日以内に返信