Expand test with a data provider to quickly add more tests data sets

This commit is contained in:
Daniel Röhrig 2019-11-13 22:20:44 +01:00
Родитель 360660da1b
Коммит 004f0b4269
1 изменённых файлов: 20 добавлений и 6 удалений

Просмотреть файл

@ -44,15 +44,29 @@ class ValidateDurationTest extends TestCase
$this->reflectedValidateDurationMethod->setAccessible(true);
}
public function testValidateCorrectTimeInterval()
/**
* @dataProvider intervalProvider
*
* @param string $interval
* @param bool $expectedResult
*/
public function testValidateCorrectTimeInterval(string $interval, bool $expectedResult)
{
$interval = 'P2Y4DT6H8M';
$this->assertTrue($this->reflectedValidateDurationMethod->invoke($this->recipeService, $interval));
if ($expectedResult) {
$this->assertTrue($this->reflectedValidateDurationMethod->invoke($this->recipeService, $interval));
} else {
$this->assertFalse($this->reflectedValidateDurationMethod->invoke($this->recipeService, $interval));
}
}
public function testValidateIncorrectTimeInterval()
/**
* @return array
*/
public function intervalProvider(): array
{
$interval = 'P2IY4DT6H8M';
$this->assertFalse($this->reflectedValidateDurationMethod->invoke($this->recipeService, $interval));
return [
['P2Y4DT6H8M', true],
['P2IY4DT6H8M', false],
];
}
}