Skip to content

Commit

Permalink
tests: port assertEquals() with delta to assertEqualsWithDelta()
Browse files Browse the repository at this point in the history
assertEquals() in phpunit 9.5 no longer takes a delta parameter
and has assertEqualsWithDelta() as a replacement. This means
float get compared without a delta atm, and a recent phpunit
release (9.5.25) has made float comparisons stricter resulting in
test suite errors such as:

1) SubtaskTimeTrackingModelTest::testCalculateSubtaskTime
Total spent
Failed asserting that 3.3000000000000003 matches expected 3.3.
tests/units/Model/SubtaskTimeTrackingModelTest.php:186

This replaces all assertEquals() calls that pass a delta value
with assertEqualsWithDelta().
  • Loading branch information
lazka authored and fguillot committed Oct 11, 2022
1 parent 2d4ee93 commit 0b8a270
Show file tree
Hide file tree
Showing 17 changed files with 82 additions and 82 deletions.
2 changes: 1 addition & 1 deletion tests/units/Action/TaskUpdateStartDateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function testAction()

$task = $taskFinderModel->getById(1);
$this->assertNotEmpty($task);
$this->assertEquals(time(), $task['date_started'], 'Date started delta', 2);
$this->assertEqualsWithDelta(time(), $task['date_started'], 2, 'Date started delta');
}

public function testWithWrongColumn()
Expand Down
8 changes: 4 additions & 4 deletions tests/units/Analytic/AverageLeadCycleTimeAnalyticTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ public function testBuild()
$stats = $averageLeadCycleTimeAnalytic->build(1);

$this->assertEquals(5, $stats['count']);
$this->assertEquals(3600 + 1800 + 3600 + 2*3600, $stats['total_lead_time'], '', 10);
$this->assertEquals(1800 + 900, $stats['total_cycle_time'], '', 5);
$this->assertEquals((3600 + 1800 + 3600 + 2*3600) / 5, $stats['avg_lead_time'], '', 5);
$this->assertEquals((1800 + 900) / 5, $stats['avg_cycle_time'], '', 5);
$this->assertEqualsWithDelta(3600 + 1800 + 3600 + 2 * 3600, $stats['total_lead_time'], 10, '');
$this->assertEqualsWithDelta(1800 + 900, $stats['total_cycle_time'], 5, '');
$this->assertEqualsWithDelta((3600 + 1800 + 3600 + 2 * 3600) / 5, $stats['avg_lead_time'], 5, '');
$this->assertEqualsWithDelta((1800 + 900) / 5, $stats['avg_cycle_time'], 5, '');
}

public function testBuildWithNoTasks()
Expand Down
32 changes: 16 additions & 16 deletions tests/units/Analytic/AverageTimeSpentColumnAnalyticTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@ public function testAverageWithNoTransitions()
$stats = $averageLeadCycleTimeAnalytic->build(1);

$this->assertEquals(2, $stats[1]['count']);
$this->assertEquals(3600+1800, $stats[1]['time_spent'], '', 3);
$this->assertEquals((int) ((3600+1800)/2), $stats[1]['average'], '', 3);
$this->assertEqualsWithDelta(3600 + 1800, $stats[1]['time_spent'], 3, '');
$this->assertEqualsWithDelta((int)((3600 + 1800) / 2), $stats[1]['average'], 3, '');
$this->assertEquals('Backlog', $stats[1]['title']);

$this->assertEquals(0, $stats[2]['count']);
$this->assertEquals(0, $stats[2]['time_spent'], '', 3);
$this->assertEquals(0, $stats[2]['average'], '', 3);
$this->assertEqualsWithDelta(0, $stats[2]['time_spent'], 3, '');
$this->assertEqualsWithDelta(0, $stats[2]['average'], 3, '');
$this->assertEquals('Ready', $stats[2]['title']);

$this->assertEquals(0, $stats[3]['count']);
$this->assertEquals(0, $stats[3]['time_spent'], '', 3);
$this->assertEquals(0, $stats[3]['average'], '', 3);
$this->assertEqualsWithDelta(0, $stats[3]['time_spent'], 3, '');
$this->assertEqualsWithDelta(0, $stats[3]['average'], 3, '');
$this->assertEquals('Work in progress', $stats[3]['title']);

$this->assertEquals(0, $stats[4]['count']);
$this->assertEquals(0, $stats[4]['time_spent'], '', 3);
$this->assertEquals(0, $stats[4]['average'], '', 3);
$this->assertEqualsWithDelta(0, $stats[4]['time_spent'], 3, '');
$this->assertEqualsWithDelta(0, $stats[4]['average'], 3, '');
$this->assertEquals('Done', $stats[4]['title']);
}

Expand Down Expand Up @@ -79,23 +79,23 @@ public function testAverageWithTransitions()
$stats = $averageLeadCycleTimeAnalytic->build(1);

$this->assertEquals(2, $stats[1]['count']);
$this->assertEquals(3600+1800, $stats[1]['time_spent'], '', 3);
$this->assertEquals((int) ((3600+1800)/2), $stats[1]['average'], '', 3);
$this->assertEqualsWithDelta(3600 + 1800, $stats[1]['time_spent'], 3, '');
$this->assertEqualsWithDelta((int)((3600 + 1800) / 2), $stats[1]['average'], 3, '');
$this->assertEquals('Backlog', $stats[1]['title']);

$this->assertEquals(0, $stats[2]['count']);
$this->assertEquals(0, $stats[2]['time_spent'], '', 3);
$this->assertEquals(0, $stats[2]['average'], '', 3);
$this->assertEqualsWithDelta(0, $stats[2]['time_spent'], 3, '');
$this->assertEqualsWithDelta(0, $stats[2]['average'], 3, '');
$this->assertEquals('Ready', $stats[2]['title']);

$this->assertEquals(2, $stats[3]['count']);
$this->assertEquals(1800, $stats[3]['time_spent'], '', 3);
$this->assertEquals(900, $stats[3]['average'], '', 3);
$this->assertEqualsWithDelta(1800, $stats[3]['time_spent'], 3, '');
$this->assertEqualsWithDelta(900, $stats[3]['average'], 3, '');
$this->assertEquals('Work in progress', $stats[3]['title']);

$this->assertEquals(0, $stats[4]['count']);
$this->assertEquals(0, $stats[4]['time_spent'], '', 3);
$this->assertEquals(0, $stats[4]['average'], '', 3);
$this->assertEqualsWithDelta(0, $stats[4]['time_spent'], 3, '');
$this->assertEqualsWithDelta(0, $stats[4]['average'], 3, '');
$this->assertEquals('Done', $stats[4]['title']);
}
}
10 changes: 5 additions & 5 deletions tests/units/Model/CommentModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ public function testCreate()
$this->assertEquals(1, $comment['task_id']);
$this->assertEquals(1, $comment['user_id']);
$this->assertEquals('admin', $comment['username']);
$this->assertEquals(time(), $comment['date_creation'], '', 3);
$this->assertEquals(time(), $comment['date_modification'], '', 3);
$this->assertEqualsWithDelta(time(), $comment['date_creation'], 3, '');
$this->assertEqualsWithDelta(time(), $comment['date_modification'], 3, '');

$comment = $commentModel->getById(2);
$this->assertNotEmpty($comment);
$this->assertEquals('bla bla', $comment['comment']);
$this->assertEquals(1, $comment['task_id']);
$this->assertEquals(0, $comment['user_id']);
$this->assertEquals('', $comment['username']);
$this->assertEquals(time(), $comment['date_creation'], '', 3);
$this->assertEquals(time(), $comment['date_modification'], '', 3);
$this->assertEqualsWithDelta(time(), $comment['date_creation'], 3, '');
$this->assertEqualsWithDelta(time(), $comment['date_modification'], 3, '');
}

public function testGetAll()
Expand Down Expand Up @@ -75,7 +75,7 @@ public function testUpdate()
$comment = $commentModel->getById(1);
$this->assertNotEmpty($comment);
$this->assertEquals('bla', $comment['comment']);
$this->assertEquals(time(), $comment['date_modification'], '', 3);
$this->assertEqualsWithDelta(time(), $comment['date_modification'], 3, '');
}

public function testRemove()
Expand Down
2 changes: 1 addition & 1 deletion tests/units/Model/ProjectActivityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function testCreation()
$events = $projectActivity->getQuery()->desc('id')->findAll();

$this->assertCount(2, $events);
$this->assertEquals(time(), $events[0]['date_creation'], '', 1);
$this->assertEqualsWithDelta(time(), $events[0]['date_creation'], 1, '');
$this->assertEquals(TaskModel::EVENT_UPDATE, $events[0]['event_name']);
$this->assertEquals(TaskModel::EVENT_CLOSE, $events[1]['event_name']);
}
Expand Down
8 changes: 4 additions & 4 deletions tests/units/Model/ProjectDailyStatsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ public function testUpdateTotals()
$this->assertEquals($expected[0]['day'], $metrics[0]['day']);
$this->assertEquals($expected[1]['day'], $metrics[1]['day']);

$this->assertEquals($expected[0]['avg_lead_time'], $metrics[0]['avg_lead_time'], '', 5);
$this->assertEquals($expected[1]['avg_lead_time'], $metrics[1]['avg_lead_time'], '', 5);
$this->assertEqualsWithDelta($expected[0]['avg_lead_time'], $metrics[0]['avg_lead_time'], 5, '');
$this->assertEqualsWithDelta($expected[1]['avg_lead_time'], $metrics[1]['avg_lead_time'], 5, '');

$this->assertEquals($expected[0]['avg_cycle_time'], $metrics[0]['avg_cycle_time'], '', 5);
$this->assertEquals($expected[1]['avg_cycle_time'], $metrics[1]['avg_cycle_time'], '', 5);
$this->assertEqualsWithDelta($expected[0]['avg_cycle_time'], $metrics[0]['avg_cycle_time'], 5, '');
$this->assertEqualsWithDelta($expected[1]['avg_cycle_time'], $metrics[1]['avg_cycle_time'], 5, '');
}
}
10 changes: 5 additions & 5 deletions tests/units/Model/ProjectFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function testCreation()
$this->assertEquals('/tmp/foo', $file['path']);
$this->assertEquals(0, $file['is_image']);
$this->assertEquals(1, $file['project_id']);
$this->assertEquals(time(), $file['date'], '', 2);
$this->assertEqualsWithDelta(time(), $file['date'], 2, '');
$this->assertEquals(0, $file['user_id']);
$this->assertEquals(10, $file['size']);

Expand Down Expand Up @@ -168,15 +168,15 @@ public function testUploadFiles()
$this->assertEquals(1, $files[0]['project_id']);
$this->assertEquals(0, $files[0]['user_id']);
$this->assertEquals(123, $files[0]['size']);
$this->assertEquals(time(), $files[0]['date'], '', 2);
$this->assertEqualsWithDelta(time(), $files[0]['date'], 2, '');

$this->assertEquals(2, $files[1]['id']);
$this->assertEquals('file2.doc', $files[1]['name']);
$this->assertEquals(0, $files[1]['is_image']);
$this->assertEquals(1, $files[1]['project_id']);
$this->assertEquals(0, $files[1]['user_id']);
$this->assertEquals(456, $files[1]['size']);
$this->assertEquals(time(), $files[1]['date'], '', 2);
$this->assertEqualsWithDelta(time(), $files[1]['date'], 2, '');
}

public function testUploadFilesWithEmptyFiles()
Expand Down Expand Up @@ -270,7 +270,7 @@ public function testUploadFileContent()
$this->assertEquals(1, $files[0]['project_id']);
$this->assertEquals(0, $files[0]['user_id']);
$this->assertEquals(4, $files[0]['size']);
$this->assertEquals(time(), $files[0]['date'], '', 2);
$this->assertEqualsWithDelta(time(), $files[0]['date'], 2, '');
}

public function testUploadImageContent()
Expand Down Expand Up @@ -306,6 +306,6 @@ public function testUploadImageContent()
$this->assertEquals(1, $files[0]['project_id']);
$this->assertEquals(0, $files[0]['user_id']);
$this->assertEquals(4, $files[0]['size']);
$this->assertEquals(time(), $files[0]['date'], '', 2);
$this->assertEqualsWithDelta(time(), $files[0]['date'], 2, '');
}
}
4 changes: 2 additions & 2 deletions tests/units/Model/ProjectModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function testCreation()
$this->assertEquals(0, $project['is_private']);
$this->assertEquals(0, $project['per_swimlane_task_limits']);
$this->assertEquals(0, $project['task_limit']);
$this->assertEquals(time(), $project['last_modified'], '', 1);
$this->assertEqualsWithDelta(time(), $project['last_modified'], 1, '');
$this->assertEmpty($project['token']);
$this->assertEmpty($project['start_date']);
$this->assertEmpty($project['end_date']);
Expand Down Expand Up @@ -191,7 +191,7 @@ public function testUpdateLastModifiedDate()

$project = $projectModel->getById(1);
$this->assertNotEmpty($project);
$this->assertEquals($now, $project['last_modified'], 'Wrong Timestamp', 1);
$this->assertEqualsWithDelta($now, $project['last_modified'], 1, 'Wrong Timestamp');

sleep(1);
$this->assertTrue($projectModel->updateModificationDate(1));
Expand Down
30 changes: 15 additions & 15 deletions tests/units/Model/SubtaskTimeTrackingModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testToggleTimerWhenFeatureDisabled()
$subtaskTimeTrackingModel = new SubtaskTimeTrackingModel($this->container);
$projectModel = new ProjectModel($this->container);

$this->assertEquals(1, $projectModel->create(array('name' => 'test1')));
$this->assertEquals(1, $projectModel->create(array('name' => 'test1')), 1);
$this->assertEquals(1, $taskCreationModel->create(array('title' => 'test 1', 'project_id' => 1, 'column_id' => 1, 'owner_id' => 1)));
$this->assertEquals(1, $subtaskModel->create(array('title' => 'subtask #2', 'task_id' => 1, 'user_id' => 1)));

Expand Down Expand Up @@ -95,12 +95,12 @@ public function testGetTimerStatus()

$subtasks = $subtaskModel->getAll(1);
$this->assertNotEmpty($subtasks);
$this->assertEquals(time(), $subtasks[0]['timer_start_date'], '', 3);
$this->assertEqualsWithDelta(time(), $subtasks[0]['timer_start_date'], 3, '');
$this->assertTrue($subtasks[0]['is_timer_started']);

$subtask = $subtaskModel->getByIdWithDetails(1);
$this->assertNotEmpty($subtask);
$this->assertEquals(time(), $subtask['timer_start_date'], '', 3);
$this->assertEqualsWithDelta(time(), $subtask['timer_start_date'], 3, '');
$this->assertTrue($subtask['is_timer_started']);

// Stop the clock
Expand Down Expand Up @@ -183,8 +183,8 @@ public function testCalculateSubtaskTime()

$time = $subtaskTimeTrackingModel->calculateSubtaskTime(1);
$this->assertCount(2, $time);
$this->assertEquals(3.3, $time['time_spent'], 'Total spent', 0.01);
$this->assertEquals(7.7, $time['time_estimated'], 'Total estimated', 0.01);
$this->assertEqualsWithDelta(3.3, $time['time_spent'], 0.01, 'Total spent');
$this->assertEqualsWithDelta(7.7, $time['time_estimated'], 0.01, 'Total estimated');
}

public function testUpdateSubtaskTimeSpent()
Expand All @@ -211,16 +211,16 @@ public function testUpdateSubtaskTimeSpent()
$timesheet = $subtaskTimeTrackingModel->getUserTimesheet(1);
$this->assertNotEmpty($timesheet);
$this->assertCount(2, $timesheet);
$this->assertEquals(3600, $timesheet[0]['end'] - $timesheet[0]['start'], 'Wrong timestamps', 1);
$this->assertEquals(3600, $timesheet[1]['end'] - $timesheet[1]['start'], 'Wrong timestamps', 1);
$this->assertEqualsWithDelta(3600, $timesheet[0]['end'] - $timesheet[0]['start'], 1, 'Wrong timestamps');
$this->assertEqualsWithDelta(3600, $timesheet[1]['end'] - $timesheet[1]['start'], 1, 'Wrong timestamps');

$time = $subtaskTimeTrackingModel->calculateSubtaskTime(1);
$this->assertEquals(4.2, $time['time_spent'], 'Total spent', 0.01);
$this->assertEquals(0, $time['time_estimated'], 'Total estimated', 0.01);
$this->assertEqualsWithDelta(4.2, $time['time_spent'], 0.01, 'Total spent');
$this->assertEqualsWithDelta(0, $time['time_estimated'], 0.01, 'Total estimated');

$time = $subtaskTimeTrackingModel->calculateSubtaskTime(2);
$this->assertEquals(0, $time['time_spent'], 'Total spent', 0.01);
$this->assertEquals(0, $time['time_estimated'], 'Total estimated', 0.01);
$this->assertEqualsWithDelta(0, $time['time_spent'], 0.01, 'Total spent');
$this->assertEqualsWithDelta(0, $time['time_estimated'], 0.01, 'Total estimated');
}

public function testUpdateTaskTimeTracking()
Expand Down Expand Up @@ -251,13 +251,13 @@ public function testUpdateTaskTimeTracking()

$task = $taskFinderModel->getById(1);
$this->assertNotEmpty($task);
$this->assertEquals(2.2, $task['time_spent'], 'Total spent', 0.01);
$this->assertEquals(1, $task['time_estimated'], 'Total estimated', 0.01);
$this->assertEqualsWithDelta(2.2, $task['time_spent'], 0.01, 'Total spent');
$this->assertEqualsWithDelta(1, $task['time_estimated'], 0.01, 'Total estimated');

$task = $taskFinderModel->getById(2);
$this->assertNotEmpty($task);
$this->assertEquals(3.4, $task['time_spent'], 'Total spent', 0.01);
$this->assertEquals(1.25, $task['time_estimated'], 'Total estimated', 0.01);
$this->assertEqualsWithDelta(3.4, $task['time_spent'], 0.01, 'Total spent');
$this->assertEqualsWithDelta(1.25, $task['time_estimated'], 0.01, 'Total estimated');

$task = $taskFinderModel->getById(3);
$this->assertNotEmpty($task);
Expand Down
6 changes: 3 additions & 3 deletions tests/units/Model/TaskCreationModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public function testMinimum()
$this->assertEquals('', $task['description']);
$this->assertEquals('', $task['reference']);

$this->assertEquals(time(), $task['date_creation'], 'Wrong timestamp', 1);
$this->assertEquals(time(), $task['date_modification'], 'Wrong timestamp', 1);
$this->assertEqualsWithDelta(time(), $task['date_creation'], 1, 'Wrong timestamp');
$this->assertEqualsWithDelta(time(), $task['date_modification'], 1, 'Wrong timestamp');
$this->assertEquals(0, $task['date_due']);
$this->assertEquals(0, $task['date_completed']);
$this->assertEquals(0, $task['date_started']);
Expand Down Expand Up @@ -302,7 +302,7 @@ public function testDateStarted()
$this->assertEquals(4, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'date_started' => time())));

$task = $taskFinderModel->getById(4);
$this->assertEquals(time(), $task['date_started'], '', 1);
$this->assertEqualsWithDelta(time(), $task['date_started'], 1, '');

// Set empty string
$this->assertEquals(5, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test', 'date_started' => '')));
Expand Down
10 changes: 5 additions & 5 deletions tests/units/Model/TaskExternalLinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public function testCreate()
$this->assertEquals('related', $link['dependency']);
$this->assertEquals('weblink', $link['link_type']);
$this->assertEquals(0, $link['creator_id']);
$this->assertEquals(time(), $link['date_modification'], '', 2);
$this->assertEquals(time(), $link['date_creation'], '', 2);
$this->assertEqualsWithDelta(time(), $link['date_modification'], 2, '');
$this->assertEqualsWithDelta(time(), $link['date_creation'], 2, '');
}

public function testCreateWithUserSession()
Expand All @@ -50,8 +50,8 @@ public function testCreateWithUserSession()
$this->assertEquals('related', $link['dependency']);
$this->assertEquals('weblink', $link['link_type']);
$this->assertEquals(1, $link['creator_id']);
$this->assertEquals(time(), $link['date_modification'], '', 2);
$this->assertEquals(time(), $link['date_creation'], '', 2);
$this->assertEqualsWithDelta(time(), $link['date_modification'], 2, '');
$this->assertEqualsWithDelta(time(), $link['date_creation'], 2, '');
}

public function testModification()
Expand All @@ -71,7 +71,7 @@ public function testModification()
$link = $taskExternalLinkModel->getById(1);
$this->assertNotEmpty($link);
$this->assertEquals('https://kanboard.org/', $link['url']);
$this->assertEquals(time(), $link['date_modification'], '', 2);
$this->assertEqualsWithDelta(time(), $link['date_modification'], 2, '');
}

public function testRemove()
Expand Down
8 changes: 4 additions & 4 deletions tests/units/Model/TaskFileModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function testCreation()
$this->assertEquals('/tmp/foo', $file['path']);
$this->assertEquals(0, $file['is_image']);
$this->assertEquals(1, $file['task_id']);
$this->assertEquals(time(), $file['date'], '', 2);
$this->assertEqualsWithDelta(time(), $file['date'], 2, '');
$this->assertEquals(0, $file['user_id']);
$this->assertEquals(10, $file['size']);

Expand Down Expand Up @@ -195,15 +195,15 @@ public function testUploadFiles()
$this->assertEquals(1, $files[0]['task_id']);
$this->assertEquals(0, $files[0]['user_id']);
$this->assertEquals(123, $files[0]['size']);
$this->assertEquals(time(), $files[0]['date'], '', 2);
$this->assertEqualsWithDelta(time(), $files[0]['date'], 2, '');

$this->assertEquals(2, $files[1]['id']);
$this->assertEquals('file2.doc', $files[1]['name']);
$this->assertEquals(0, $files[1]['is_image']);
$this->assertEquals(1, $files[1]['task_id']);
$this->assertEquals(0, $files[1]['user_id']);
$this->assertEquals(456, $files[1]['size']);
$this->assertEquals(time(), $files[1]['date'], '', 2);
$this->assertEqualsWithDelta(time(), $files[1]['date'], 2, '');
}

public function testUploadFilesWithEmptyFiles()
Expand Down Expand Up @@ -299,7 +299,7 @@ public function testUploadFileContent()
$this->assertEquals(1, $files[0]['task_id']);
$this->assertEquals(0, $files[0]['user_id']);
$this->assertEquals(4, $files[0]['size']);
$this->assertEquals(time(), $files[0]['date'], '', 2);
$this->assertEqualsWithDelta(time(), $files[0]['date'], 2, '');
}

public function testUploadFileContentWithObjectStorageError()
Expand Down

0 comments on commit 0b8a270

Please sign in to comment.