Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: port assertEquals() with delta to assertEqualsWithDelta() #5078

Merged
merged 1 commit into from Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/units/Action/TaskUpdateStartDateTest.php
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
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
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
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
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
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
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
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
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
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
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
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