Completed
Push — master ( 08f930...54ffd8 )
by David de
02:36
created

ValueConverter/DateTimeValueConverterTest.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Port\Tests\ValueConverter;
4
5
use Port\ValueConverter\DateTimeValueConverter;
6
7
class DateTimeValueConverterTest extends \PHPUnit_Framework_TestCase
8
{
9 View Code Duplication
    public function testConvertWithoutInputOrOutputFormatReturnsDateTimeInstance()
10
    {
11
        $value = '2011-10-20 13:05';
12
        $converter = new DateTimeValueConverter;
13
        $output = call_user_func($converter, $value);
14
        $this->assertInstanceOf('\DateTime', $output);
15
        $this->assertEquals('13', $output->format('H'));
16
    }
17
18 View Code Duplication
    public function testConvertWithFormatReturnsDateTimeInstance()
19
    {
20
        $value = '14/10/2008 09:40:20';
21
        $converter = new DateTimeValueConverter('d/m/Y H:i:s');
22
        $output = call_user_func($converter, $value);
23
        $this->assertInstanceOf('\DateTime', $output);
24
        $this->assertEquals('20', $output->format('s'));
25
    }
26
27 View Code Duplication
    public function testConvertWithInputAndOutputFormatReturnsString()
28
    {
29
        $value = '14/10/2008 09:40:20';
30
        $converter = new DateTimeValueConverter('d/m/Y H:i:s', 'd-M-Y');
31
        $output = call_user_func($converter, $value);
32
        $this->assertEquals('14-Oct-2008', $output);
33
    }
34
35 View Code Duplication
    public function testConvertWithNoInputStringWithOutputFormatReturnsString()
36
    {
37
        $value = '2011-10-20 13:05';
38
        $converter = new DateTimeValueConverter(null, 'd-M-Y');
39
        $output = call_user_func($converter, $value);
40
        $this->assertEquals('20-Oct-2011', $output);
41
42
    }
43
44
    public function testInvalidInputFormatThrowsException()
45
    {
46
        $value = '14/10/2008 09:40:20';
47
        $converter = new DateTimeValueConverter('d-m-y', 'd-M-Y');
48
        $this->setExpectedException("UnexpectedValueException", "14/10/2008 09:40:20 is not a valid date/time according to format d-m-y");
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
49
        call_user_func($converter, $value);
50
    }
51
52
    public function testNullIsReturnedIfNullPassed()
53
    {
54
        $converter = new DateTimeValueConverter('d-m-y', 'd-M-Y');
55
        $this->assertNull(call_user_func($converter, null));
56
    }
57
}
58