From 73ff5ec89b711791b3993f9158dc9554a623602c Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 16 Jan 2016 17:01:56 -0500 Subject: Remove ProjectAnalytic class --- .../Analytic/AverageLeadCycleTimeAnalyticTest.php | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 tests/units/Analytic/AverageLeadCycleTimeAnalyticTest.php (limited to 'tests/units/Analytic/AverageLeadCycleTimeAnalyticTest.php') diff --git a/tests/units/Analytic/AverageLeadCycleTimeAnalyticTest.php b/tests/units/Analytic/AverageLeadCycleTimeAnalyticTest.php new file mode 100644 index 00000000..9c445dca --- /dev/null +++ b/tests/units/Analytic/AverageLeadCycleTimeAnalyticTest.php @@ -0,0 +1,73 @@ +container); + $projectModel = new Project($this->container); + $averageLeadCycleTimeAnalytic = new AverageLeadCycleTimeAnalytic($this->container); + $now = time(); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test1'))); + + $this->assertEquals(1, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(2, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(3, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + $this->assertEquals(4, $taskCreationModel->create(array('project_id' => 1, 'title' => 'test'))); + + // LT=3600 CT=1800 + $this->container['db']->table(Task::TABLE)->eq('id', 1)->update(array('date_completed' => $now + 3600, 'date_started' => $now + 1800)); + + // LT=1800 CT=900 + $this->container['db']->table(Task::TABLE)->eq('id', 2)->update(array('date_completed' => $now + 1800, 'date_started' => $now + 900)); + + // LT=3600 CT=0 + $this->container['db']->table(Task::TABLE)->eq('id', 3)->update(array('date_completed' => $now + 3600)); + + // LT=2*3600 CT=0 + $this->container['db']->table(Task::TABLE)->eq('id', 4)->update(array('date_completed' => $now + 2 * 3600)); + + $stats = $averageLeadCycleTimeAnalytic->build(1); + $expected = array( + 'count' => 4, + 'total_lead_time' => 3600 + 1800 + 3600 + 2*3600, + 'total_cycle_time' => 1800 + 900, + 'avg_lead_time' => (3600 + 1800 + 3600 + 2*3600) / 4, + 'avg_cycle_time' => (1800 + 900) / 4, + ); + + $this->assertEquals($expected, $stats); + } + + public function testBuildWithNoTasks() + { + $taskCreationModel = new TaskCreation($this->container); + $projectModel = new Project($this->container); + $averageLeadCycleTimeAnalytic = new AverageLeadCycleTimeAnalytic($this->container); + $now = time(); + + $this->assertEquals(1, $projectModel->create(array('name' => 'test1'))); + $this->assertEquals(2, $projectModel->create(array('name' => 'test1'))); + + $stats = $averageLeadCycleTimeAnalytic->build(1); + + $expected = array( + 'count' => 0, + 'total_lead_time' => 0, + 'total_cycle_time' => 0, + 'avg_lead_time' => 0, + 'avg_cycle_time' => 0, + ); + + $this->assertEquals($expected, $stats); + } +} -- cgit v1.3.1 From da7259819bb6c3947317b39fc2a10626471bfca3 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 20 Feb 2016 15:42:15 -0500 Subject: Rewrite assertion to avoid false positive on the CI --- tests/units/Analytic/AverageLeadCycleTimeAnalyticTest.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'tests/units/Analytic/AverageLeadCycleTimeAnalyticTest.php') diff --git a/tests/units/Analytic/AverageLeadCycleTimeAnalyticTest.php b/tests/units/Analytic/AverageLeadCycleTimeAnalyticTest.php index 9c445dca..b8faec6c 100644 --- a/tests/units/Analytic/AverageLeadCycleTimeAnalyticTest.php +++ b/tests/units/Analytic/AverageLeadCycleTimeAnalyticTest.php @@ -37,15 +37,12 @@ class AverageLeadCycleTimeAnalyticTest extends Base $this->container['db']->table(Task::TABLE)->eq('id', 4)->update(array('date_completed' => $now + 2 * 3600)); $stats = $averageLeadCycleTimeAnalytic->build(1); - $expected = array( - 'count' => 4, - 'total_lead_time' => 3600 + 1800 + 3600 + 2*3600, - 'total_cycle_time' => 1800 + 900, - 'avg_lead_time' => (3600 + 1800 + 3600 + 2*3600) / 4, - 'avg_cycle_time' => (1800 + 900) / 4, - ); - $this->assertEquals($expected, $stats); + $this->assertEquals(4, $stats['count']); + $this->assertEquals(3600 + 1800 + 3600 + 2*3600, $stats['total_lead_time'], '', 5); + $this->assertEquals(1800 + 900, $stats['total_cycle_time'], '', 5); + $this->assertEquals((3600 + 1800 + 3600 + 2*3600) / 4, $stats['avg_lead_time'], '', 5); + $this->assertEquals((1800 + 900) / 4, $stats['avg_cycle_time'], '', 5); } public function testBuildWithNoTasks() -- cgit v1.3.1