Completed
Push — master ( 92bd35...fb5c6c )
by Tom
04:10
created

TimeElapsedTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 60
c 0
b 0
f 0
wmc 6
lcom 0
cbo 2
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A invocation() 0 5 1
A provideCalculations() 0 18 1
A fullAndShortCalculations() 0 5 2
A negativeTimestampNotHandleable() 0 5 1
A invalidDatetime() 0 4 1
1
<?php
2
/*
3
 * @author Tom Klingenberg <https://github.com/ktomk>
4
 */
5
6
namespace N98\Util;
7
8
class TimeElapsedTest extends \PHPUnit_Framework_TestCase
9
{
10
    /**
11
     * @test
12
     */
13
    public function invocation()
14
    {
15
        $string = TimeElapsed::full(0);
16
        $this->assertInternalType('string', $string);
17
    }
18
19
    public function provideCalculations()
20
    {
21
        return array(
22
            array('just now', 0, 0),
23
            array('just now', 0, null),
24
            array('1 second ago', 1, 1),
25
            array('1 second ago', 1, null),
26
            array('2 seconds ago', 2, 2),
27
            array('2 seconds ago', 2, null),
28
            array('1 second ago', ' 2012-12-12T13:44:40Z', 1355319881),
29
            array(
30
                '85 years, 10 months, 3 weeks, 1 day, 3 hours, 29 minutes, 21 seconds ago',
31
                ' 2012-12-12T13:44:40Z',
32
                -1355319881,
33
                '85 years ago',
34
            ),
35
        );
36
    }
37
38
    /**
39
     * @test
40
     * @dataProvider provideCalculations
41
     */
42
    public function fullAndShortCalculations($full, $datetimeOrSeconds, $now, $short = null)
43
    {
44
        $this->assertEquals($full, TimeElapsed::full($datetimeOrSeconds, $now));
45
        $this->assertEquals($short ?: $full, TimeElapsed::short($datetimeOrSeconds, $now));
46
    }
47
48
    /**
49
     * @test
50
     * @expectedException \BadMethodCallException
51
     */
52
    public function negativeTimestampNotHandleable()
53
    {
54
        // one second in the past at the beginng of time
55
        TimeElapsed::full(1, 0);
56
    }
57
58
    /**
59
     * @test
60
     * @expectedException \Exception
61
     * @expectedExceptionMessage DateTime::__construct():
62
     */
63
    public function invalidDatetime()
64
    {
65
        TimeElapsed::full(' 0000----12T13:44:40Z', 0);
66
    }
67
}
68