2
2
3
3
namespace Doctrine \Tests \DBAL \Types ;
4
4
5
+ use Doctrine \DBAL \Types \ConversionException ;
6
+ use Doctrine \DBAL \Types \DateIntervalType ;
5
7
use Doctrine \DBAL \Types \Type ;
6
8
use Doctrine \Tests \DBAL \Mocks \MockPlatform ;
9
+ use Doctrine \Tests \DbalTestCase ;
7
10
8
- class DateIntervalTest extends \ Doctrine \ Tests \ DbalTestCase
11
+ final class DateIntervalTest extends DbalTestCase
9
12
{
10
13
/**
11
14
* @var MockPlatform
@@ -20,66 +23,84 @@ class DateIntervalTest extends \Doctrine\Tests\DbalTestCase
20
23
/**
21
24
* {@inheritDoc}
22
25
*/
23
- protected function setUp ()
26
+ protected function setUp () : void
24
27
{
25
28
$ this ->platform = new MockPlatform ();
26
29
$ this ->type = Type::getType ('dateinterval ' );
27
30
28
- self ::assertInstanceOf (' Doctrine\DBAL\Types\ DateIntervalType' , $ this ->type );
31
+ self ::assertInstanceOf (DateIntervalType::class , $ this ->type );
29
32
}
30
33
31
- public function testDateIntervalConvertsToDatabaseValue ()
34
+ public function testDateIntervalConvertsToDatabaseValue () : void
32
35
{
33
36
$ interval = new \DateInterval ('P2Y1DT1H2M3S ' );
34
37
35
- $ expected = 'P02Y00M01DT01H02M03S ' ;
38
+ $ expected = '+ P02Y00M01DT01H02M03S ' ;
36
39
$ actual = $ this ->type ->convertToDatabaseValue ($ interval , $ this ->platform );
37
40
38
41
self ::assertEquals ($ expected , $ actual );
39
42
}
40
43
41
- public function testDateIntervalConvertsToPHPValue ()
44
+ public function testDateIntervalConvertsToPHPValue () : void
42
45
{
43
- $ date = $ this ->type ->convertToPHPValue ('P02Y00M01DT01H02M03S ' , $ this ->platform );
44
- self ::assertInstanceOf ('DateInterval ' , $ date );
45
- self ::assertEquals ('P02Y00M01DT01H02M03S ' , $ date ->format ('P%YY%MM%DDT%HH%IM%SS ' ));
46
+ $ interval = $ this ->type ->convertToPHPValue ('+P02Y00M01DT01H02M03S ' , $ this ->platform );
47
+
48
+ self ::assertInstanceOf (\DateInterval::class, $ interval );
49
+ self ::assertEquals ('+P02Y00M01DT01H02M03S ' , $ interval ->format (DateIntervalType::FORMAT ));
50
+ }
51
+
52
+ public function testNegativeDateIntervalConvertsToDatabaseValue () : void
53
+ {
54
+ $ interval = new \DateInterval ('P2Y1DT1H2M3S ' );
55
+ $ interval ->invert = 1 ;
56
+
57
+ $ actual = $ this ->type ->convertToDatabaseValue ($ interval , $ this ->platform );
58
+
59
+ self ::assertEquals ('-P02Y00M01DT01H02M03S ' , $ actual );
60
+ }
61
+
62
+ public function testNegativeDateIntervalConvertsToPHPValue () : void
63
+ {
64
+ $ interval = $ this ->type ->convertToPHPValue ('-P02Y00M01DT01H02M03S ' , $ this ->platform );
65
+
66
+ self ::assertInstanceOf (\DateInterval::class, $ interval );
67
+ self ::assertEquals ('-P02Y00M01DT01H02M03S ' , $ interval ->format (DateIntervalType::FORMAT ));
46
68
}
47
69
48
- public function testInvalidDateIntervalFormatConversion ()
70
+ public function testInvalidDateIntervalFormatConversion () : void
49
71
{
50
- $ this ->expectException ('Doctrine\DBAL\Types\ConversionException ' );
72
+ $ this ->expectException (ConversionException::class);
73
+
51
74
$ this ->type ->convertToPHPValue ('abcdefg ' , $ this ->platform );
52
75
}
53
76
54
- public function testDateIntervalNullConversion ()
77
+ public function testDateIntervalNullConversion () : void
55
78
{
56
79
self ::assertNull ($ this ->type ->convertToPHPValue (null , $ this ->platform ));
57
80
}
58
81
59
82
/**
60
83
* @group DBAL-1288
61
84
*/
62
- public function testRequiresSQLCommentHint ()
85
+ public function testRequiresSQLCommentHint () : void
63
86
{
64
87
self ::assertTrue ($ this ->type ->requiresSQLCommentHint ($ this ->platform ));
65
88
}
66
89
67
90
/**
68
91
* @dataProvider invalidPHPValuesProvider
69
- *
70
- * @param mixed $value
71
92
*/
72
- public function testInvalidTypeConversionToDatabaseValue ($ value )
93
+ public function testInvalidTypeConversionToDatabaseValue ($ value ) : void
73
94
{
74
- $ this ->expectException (' Doctrine\DBAL\Types\ ConversionException' );
95
+ $ this ->expectException (ConversionException::class );
75
96
76
97
$ this ->type ->convertToDatabaseValue ($ value , $ this ->platform );
77
98
}
78
99
79
100
/**
80
101
* @return mixed[][]
81
102
*/
82
- public function invalidPHPValuesProvider ()
103
+ public function invalidPHPValuesProvider () : array
83
104
{
84
105
return [
85
106
[0 ],
0 commit comments