Failed Conditions
Pull Request — master (#2763)
by Alexandre
04:52
created

testNegativeDateIntervalConvertsToDatabaseValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 10
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 10
loc 10
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace Doctrine\Tests\DBAL\Types;
4
5
use Doctrine\DBAL\Types\Type;
6
use Doctrine\Tests\DBAL\Mocks\MockPlatform;
7
8
class DateIntervalTest  extends \Doctrine\Tests\DbalTestCase
0 ignored issues
show
Coding Style introduced by
Expected 1 space after class name; 2 found
Loading history...
Coding Style introduced by
Expected 1 space before extends keyword; 2 found
Loading history...
9
{
10
    /**
11
     * @var MockPlatform
12
     */
13
    private $platform;
14
15
    /**
16
     * @var \Doctrine\DBAL\Types\DateIntervalType
17
     */
18
    private $type;
19
20
    /**
21
     * {@inheritDoc}
22
     */
23
    protected function setUp()
24
    {
25
        $this->platform = new MockPlatform();
26
        $this->type     = Type::getType('dateinterval');
27
28
        $this->assertInstanceOf('Doctrine\DBAL\Types\DateIntervalType', $this->type);
29
    }
30
31 View Code Duplication
    public function testDateIntervalConvertsToDatabaseValue()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
32
    {
33
        $interval = new \DateInterval('P2Y1DT1H2M3S');
34
35
        $expected = '+P0002-00-01T01:02:03';
36
        $actual = $this->type->convertToDatabaseValue($interval, $this->platform);
37
38
        $this->assertEquals($expected, $actual);
39
    }
40
41
    public function testDateIntervalConvertsToPHPValue()
42
    {
43
        $interval = $this->type->convertToPHPValue('+P0002-00-01T01:02:03', $this->platform);
44
        $this->assertInstanceOf('DateInterval', $interval);
45
        $this->assertEquals('+P2Y0M1DT1H2M3S', $interval->format('%RP%yY%mM%dDT%hH%iM%sS'));
46
    }
47
48
    public function testOldDateIntervalFormatConvertsToPHPValue()
49
    {
50
        $interval = $this->type->convertToPHPValue('P0002-00-01T01:02:03', $this->platform);
51
        $this->assertInstanceOf('DateInterval', $interval);
52
        $this->assertEquals('+P2Y0M1DT1H2M3S', $interval->format('%RP%yY%mM%dDT%hH%iM%sS'));
53
    }
54
55 View Code Duplication
    public function testNegativeDateIntervalConvertsToDatabaseValue()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
    {
57
        $interval = new \DateInterval('P2Y1DT1H2M3S');
58
        $interval->invert = 1;
59
60
        $expected = '-P0002-00-01T01:02:03';
61
        $actual = $this->type->convertToDatabaseValue($interval, $this->platform);
62
63
        $this->assertEquals($expected, $actual);
64
    }
65
66
    public function testNegativeDateIntervalConvertsToPHPValue()
67
    {
68
        $interval = $this->type->convertToPHPValue('-P0002-00-01T01:02:03', $this->platform);
69
        $this->assertInstanceOf('DateInterval', $interval);
70
        $this->assertEquals('-P2Y0M1DT1H2M3S', $interval->format('%RP%yY%mM%dDT%hH%iM%sS'));
71
    }
72
73
    public function testInvalidDateIntervalFormatConversion()
74
    {
75
        $this->setExpectedException('Doctrine\DBAL\Types\ConversionException');
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...
76
        $this->type->convertToPHPValue('abcdefg', $this->platform);
77
    }
78
79
    public function testDateIntervalNullConversion()
80
    {
81
        $this->assertNull($this->type->convertToPHPValue(null, $this->platform));
82
    }
83
84
    /**
85
     * @group DBAL-1288
86
     */
87
    public function testRequiresSQLCommentHint()
88
    {
89
        $this->assertTrue($this->type->requiresSQLCommentHint($this->platform));
90
    }
91
92
    /**
93
     * @dataProvider invalidPHPValuesProvider
94
     *
95
     * @param mixed $value
96
     */
97
    public function testInvalidTypeConversionToDatabaseValue($value)
98
    {
99
        $this->setExpectedException('Doctrine\DBAL\Types\ConversionException');
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...
100
101
        $this->type->convertToDatabaseValue($value, $this->platform);
102
    }
103
104
    /**
105
     * @return mixed[][]
106
     */
107 View Code Duplication
    public function invalidPHPValuesProvider()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
108
    {
109
        return [
110
            [0],
111
            [''],
112
            ['foo'],
113
            ['10:11:12'],
114
            ['2015-01-31'],
115
            ['2015-01-31 10:11:12'],
116
            [new \stdClass()],
117
            [$this],
118
            [27],
119
            [-1],
120
            [1.2],
121
            [[]],
122
            [['an array']],
123
            [new \DateTime()],
124
        ];
125
    }
126
}
127