summaryrefslogtreecommitdiff
path: root/tests/units/Model/ProjectDailyStatsTest.php
blob: 60afc4c338373a1a2fe04137abdf98dd9a4e9dcc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php

require_once __DIR__.'/../Base.php';

use Kanboard\Model\Project;
use Kanboard\Model\ProjectDailyStats;
use Kanboard\Model\TaskCreation;
use Kanboard\Model\TaskStatus;

class ProjectDailyStatsTest extends Base
{
    public function testUpdateTotals()
    {
        $p = new Project($this->container);
        $pds = new ProjectDailyStats($this->container);
        $tc = new TaskCreation($this->container);
        $ts = new TaskStatus($this->container);

        $this->assertEquals(1, $p->create(array('name' => 'UnitTest')));
        $this->assertEquals(2, $p->create(array('name' => 'UnitTest')));

        $this->assertEquals(1, $tc->create(array('title' => 'Task #1', 'project_id' => 1, 'date_started' => strtotime('-1 day'))));
        $this->assertEquals(2, $tc->create(array('title' => 'Task #2', 'project_id' => 1)));
        $this->assertEquals(3, $tc->create(array('title' => 'Task #3', 'project_id' => 2)));

        $pds->updateTotals(1, date('Y-m-d', strtotime('-1 day')));

        $this->assertTrue($ts->close(1));
        $pds->updateTotals(1, date('Y-m-d'));

        $metrics = $pds->getRawMetrics(1, date('Y-m-d', strtotime('-1days')), date('Y-m-d'));
        $expected = array(
            array(
                'day' => date('Y-m-d', strtotime('-1days')),
                'avg_lead_time' => 0,
                'avg_cycle_time' => 43200,
            ),
            array(
                'day' => date('Y-m-d'),
                'avg_lead_time' => 0,
                'avg_cycle_time' => 43200,
            )
        );

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

        $this->assertSame($expected[0]['avg_lead_time'], $metrics[0]['avg_lead_time'], '', 2);
        $this->assertSame($expected[1]['avg_lead_time'], $metrics[1]['avg_lead_time'], '', 2);

        $this->assertSame($expected[0]['avg_cycle_time'], $metrics[0]['avg_cycle_time'], '', 2);
        $this->assertSame($expected[1]['avg_cycle_time'], $metrics[1]['avg_cycle_time'], '', 2);
    }
}