Copy-paste gaps in rule tests: `DateTime`/`Time` tests check `Date`, and `Integer` has no contract tests
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 86/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- php
- 領域
- testing-qa
調査の方向性
tests/Rule/Date/DateTimeTest.php、tests/Rule/Date/TimeTest.php、NumberTest から始め、testGetName()、testSkipOnError()、testWhen() を確認します。既存の Date および Number のテストをパターンとして使用し、その後、影響を受けるルールのテストを実行して、DateTime、Time、Integer のそれぞれにこれらの契約チェックがあることを確認します。
索引モデルが issue の本文から書いたものです。
説明
What steps will reproduce the problem?
1. DateTimeTest and TimeTest test the Date rule instead of their own rule.
Three methods in tests/Rule/Date/DateTimeTest.php and tests/Rule/Date/TimeTest.php create new Date() instead of new DateTime() / new Time():
public function testGetName(): void
{
$rule = new Date(); // should be new DateTime() / new Time()
$this->assertSame('date', $rule->getName());
}
public function testSkipOnError(): void
{
$this->testSkipOnErrorInternal(new Date(), new Date(skipOnError: true));
}
public function testWhen(): void
{
$this->testWhenInternal(
new Date(),
new Date(when: static fn(mixed $value): bool => $value !== null),
);
}
So getName(), skipOnError and when are never tested for DateTime and Time. DateTest already covers Date, so these checks only run twice more on the same rule.
2. The Integer rule has no tests for getName(), skipOnError and when.
Integer has no test class of its own. NumberTest checks how Integer validates values (dataValidationPassed()/dataValidationFailed()), but testGetName(), testSkipOnError() and testWhen() there only use new Number(). AbstractNumber::getName() returns static::class, so Integer returns its own name, and no test checks that.
What is the expected result?
Every rule has these contract checks run on an instance of that rule.
What do you get instead?
DateTime, Time and Integer are not covered. A regression in their getName(), skipOnError() or when() would go unnoticed. For example: an override in the class, a missing trait after a refactoring, or a wrong default in the constructor.
Suggested fix
-
In
DateTimeTest/TimeTest, replaceDatewithDateTime/Timein the three methods above.getName()returns'date'for all of them (fromBaseDate), so the expected value stays the same. -
Add
testIntegerGetName(),testIntegerSkipOnError()andtestIntegerWhen()toNumberTest, or split them into a separateIntegerTest:public function testIntegerSkipOnError(): void { $this->testSkipOnErrorInternal(new Integer(), new Integer(skipOnError: true)); } -
Optionally, prevent this kind of copy-paste mistake: add one data-provider test that runs the
skipOnError/whenchecks over a list of all rules, instead of a separate method in each test class. Then adding a new rule means adding one line to the provider. The#[DataProvider]returns rule × option pairs (skipOnError,when); each pair gives a factory, the option name, its default, a new value and the getter name.
Additional info
| Q | A |
|---|---|
| Version | 2.x-dev (9be0c31) |
| PHP version | any |
| Operating system | any |
- 主要言語
- PHP
- スター
- 167
- フォーク
- 47
- 平均マージ
- 1日 16時間
- マージ済み PR(30日)
- 4
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
yiisoft/validator のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 65/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 62/100
yiisoft/validator の issue をすべて見る
似ている issue
-
sync-en
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
bug Feature: Kiosk
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
Infrastructure: actions Module: zmscitizenapi Module: zmsentities php Type: Bug unit tests
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
it-at-m/eappointment#3480 ·
メンテナーはふだん 1 日以内に返信
-
HttpClient
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
CI: composer install fails — league/flysystem 1.x blocked by security advisory GHSA-cxf4-7mrp-vvprオープンdevops type: bug
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 1 日以内に返信