Copy-paste gaps in rule tests: `DateTime`/`Time` tests check `Date`, and `Integer` has no contract tests
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 86/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- php
- Área
- testing-qa
Línea de trabajo
Comienza con tests/Rule/Date/DateTimeTest.php, tests/Rule/Date/TimeTest.php y NumberTest, revisando testGetName(), testSkipOnError() y testWhen(). Usa los tests existentes de Date y Number como patrones y luego ejecuta los tests de las reglas afectadas para confirmar que DateTime, Time e Integer tienen cada uno estas comprobaciones del contrato.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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 |
- Lenguaje dominante
- PHP
- Estrellas
- 167
- Forks
- 47
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 3
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de yiisoft/validator
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
-
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
-
Dificultad 3/5 1-2 días Aptitud para principiantes 65/100
-
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
-
Multibyte trim supportAbierto
Dificultad 3/5 1-2 días Aptitud para principiantes 62/100
Todos los issues de yiisoft/validator
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Automattic/static-site-importer#1879 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
521xueweihan/HelloGitHub#3790 ·
-
[Bug] Feed date, title and author too long to fit inside article box on smaller screens, mobileAbiertoBug (unconfirmed) Good first issue 1️⃣ help wanted UI :art:
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
FreshRSS/FreshRSS#9360 · 2 comentarios ·
Los mantenedores suelen responder en 1 día