Completed
Push — master ( bc4f39...bfef40 )
by Mantas
03:23
created

TimeFormatTraitTest::testFormatTimeObject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

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