mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2025-01-08 17:02:41 +00:00
Munge off-by-one dates in tests; fixes #112
This commit is contained in:
parent
5cdcd2a7d3
commit
3e42fbdddf
2 changed files with 27 additions and 0 deletions
|
@ -29,7 +29,22 @@ abstract class AbstractTest extends \PHPUnit\Framework\TestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public function approximateTime($exp, $act) {
|
||||
if (is_null($act)) {
|
||||
return null;
|
||||
}
|
||||
$target = Date::normalize($exp)->getTimeStamp();
|
||||
$value = Date::normalize($act)->getTimeStamp();
|
||||
if ($value >= ($target - 1) && $value <= ($target + 1)) {
|
||||
// if the actual time is off by no more than one second, it's acceptable
|
||||
return $exp;
|
||||
} else {
|
||||
return $act;
|
||||
}
|
||||
}
|
||||
|
||||
public function assertTime($exp, $test, string $msg = null) {
|
||||
$test = $this->approximateTime($exp, $test);
|
||||
$exp = Date::transform($exp, "iso8601");
|
||||
$test = Date::transform($test, "iso8601");
|
||||
$this->assertSame($exp, $test, $msg);
|
||||
|
|
|
@ -82,11 +82,23 @@ trait Setup {
|
|||
public function compareExpectations(array $expected): bool {
|
||||
foreach ($expected as $table => $info) {
|
||||
$cols = implode(",", array_keys($info['columns']));
|
||||
$types = $info['columns'];
|
||||
$data = $this->drv->prepare("SELECT $cols from $table")->run()->getAll();
|
||||
$cols = array_keys($info['columns']);
|
||||
foreach ($info['rows'] as $index => $row) {
|
||||
$this->assertCount(sizeof($cols), $row, "The number of values for array index $index does not match the number of fields");
|
||||
$row = array_combine($cols, $row);
|
||||
foreach($data as $index => $test) {
|
||||
foreach ($test as $col => $value) {
|
||||
if ($types[$col]=="datetime") {
|
||||
$test[$col] = $this->approximateTime($row[$col], $value);
|
||||
}
|
||||
}
|
||||
if($row===$test) {
|
||||
$data[$index] = $test;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->assertContains($row, $data, "Table $table does not contain record at array index $index.");
|
||||
$found = array_search($row, $data, true);
|
||||
unset($data[$found]);
|
||||
|
|
Loading…
Reference in a new issue