Completed
Branch master (9b1797)
by Mantas
11:40
created

TimeFormatTraitTest::testFormatTimeCustom()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 8
rs 9.4286
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace MVar\Apache2LogParser;
4
5
class TimeFormatTraitTest extends \PHPUnit_Framework_TestCase
6
{
7
    /**
8
     * Test for formatTime() in case no format was set.
9
     */
10
    public function testFormatTimeNoFormatting()
11
    {
12
        /** @var TimeFormatTrait $formatter */
13
        $formatter = $this->getMockForTrait('MVar\Apache2LogParser\TimeFormatTrait');
14
15
        $this->assertEquals('no formatting', $formatter->formatTime('no formatting'));
16
    }
17
18
    /**
19
     * Test for formatTime() in case object was requested.
20
     */
21
    public function testFormatTimeObject()
22
    {
23
        /** @var TimeFormatTrait $formatter */
24
        $formatter = $this->getMockForTrait('MVar\Apache2LogParser\TimeFormatTrait');
25
        $formatter->setTimeFormat(true);
26
27
        $dateTime = new \DateTime();
28
29
        $this->assertEquals($dateTime, $formatter->formatTime($dateTime->format(\DateTime::ISO8601)));
30
    }
31
32
    /**
33
     * Test for formatTime() in case custom format was set.
34
     */
35
    public function testFormatTimeCustom()
36
    {
37
        /** @var TimeFormatTrait $formatter */
38
        $formatter = $this->getMockForTrait('MVar\Apache2LogParser\TimeFormatTrait');
39
        $formatter->setTimeFormat('d/m/Y H:i:s');
40
41
        $this->assertEquals('05/12/2015 12:00:00', $formatter->formatTime('2015-12-05 12:00:00'));
42
    }
43
}
44