@@ -32,6 +32,35 @@ public function test_it_creates_a_new_instance()
32
32
$ this ->assertInstanceOf (DateTimeInterval::class, $ DeepLinkResources );
33
33
}
34
34
35
+ public function test_it_instantiates_with_null_start_end_values ()
36
+ {
37
+ $ dateTimeInterval = new DateTimeInterval (null , null );
38
+
39
+ $ this ->assertInstanceOf (DateTimeInterval::class, $ dateTimeInterval );
40
+ $ this ->assertNull ($ dateTimeInterval ->getStart ());
41
+ $ this ->assertNull ($ dateTimeInterval ->getEnd ());
42
+ }
43
+
44
+ public function test_it_instantiates_with_null_start ()
45
+ {
46
+ $ end = date_create ('+1 day ' );
47
+ $ dateTimeInterval = new DateTimeInterval (null , $ end );
48
+
49
+ $ this ->assertInstanceOf (DateTimeInterval::class, $ dateTimeInterval );
50
+ $ this ->assertNull ($ dateTimeInterval ->getStart ());
51
+ $ this ->assertEquals ($ end , $ dateTimeInterval ->getEnd ());
52
+ }
53
+
54
+ public function test_it_instantiates_with_null_end ()
55
+ {
56
+ $ start = date_create ();
57
+ $ dateTimeInterval = new DateTimeInterval ($ start , null );
58
+
59
+ $ this ->assertInstanceOf (DateTimeInterval::class, $ dateTimeInterval );
60
+ $ this ->assertEquals ($ start , $ dateTimeInterval ->getStart ());
61
+ $ this ->assertNull ($ dateTimeInterval ->getEnd ());
62
+ }
63
+
35
64
public function test_it_gets_start ()
36
65
{
37
66
$ result = $ this ->dateTimeInterval ->getStart ();
@@ -66,15 +95,62 @@ public function test_it_sets_end()
66
95
$ this ->assertEquals ($ expected , $ this ->dateTimeInterval ->getEnd ());
67
96
}
68
97
69
- public function test_it_throws_exception_when_creating_array_with_both_properties_null ()
98
+ public function test_it_sets_start_to_null ()
99
+ {
100
+ $ result = $ this ->dateTimeInterval ->setStart (null );
101
+
102
+ $ this ->assertSame ($ this ->dateTimeInterval , $ result );
103
+ $ this ->assertNull ($ this ->dateTimeInterval ->getStart ());
104
+ }
105
+
106
+ public function test_it_sets_end_to_null ()
107
+ {
108
+ $ result = $ this ->dateTimeInterval ->setEnd (null );
109
+
110
+ $ this ->assertSame ($ this ->dateTimeInterval , $ result );
111
+ $ this ->assertNull ($ this ->dateTimeInterval ->getEnd ());
112
+ }
113
+
114
+ public function test_it_creates_array_with_null_start ()
115
+ {
116
+ $ expectedEnd = date_create ('+1 day ' );
117
+ $ expected = [
118
+ 'endDateTime ' => $ expectedEnd ->format (DateTime::ATOM ),
119
+ ];
120
+
121
+ $ this ->dateTimeInterval ->setStart (null );
122
+ $ this ->dateTimeInterval ->setEnd ($ expectedEnd );
123
+
124
+ $ result = $ this ->dateTimeInterval ->toArray ();
125
+
126
+ $ this ->assertEquals ($ expected , $ result );
127
+ }
128
+
129
+ public function test_it_creates_array_with_null_end ()
70
130
{
131
+ $ expectedStart = date_create ('+1 day ' );
132
+ $ expected = [
133
+ 'startDateTime ' => $ expectedStart ->format (DateTime::ATOM ),
134
+ ];
135
+
136
+ $ this ->dateTimeInterval ->setStart ($ expectedStart );
137
+ $ this ->dateTimeInterval ->setEnd (null );
138
+
139
+ $ result = $ this ->dateTimeInterval ->toArray ();
140
+
141
+ $ this ->assertEquals ($ expected , $ result );
142
+ }
143
+
144
+ public function test_it_creates_array_with_both_null ()
145
+ {
146
+ $ expected = [];
147
+
71
148
$ this ->dateTimeInterval ->setStart (null );
72
149
$ this ->dateTimeInterval ->setEnd (null );
73
150
74
- $ this ->expectException (LtiException::class);
75
- $ this ->expectExceptionMessage (DateTimeInterval::ERROR_NO_START_OR_END );
151
+ $ result = $ this ->dateTimeInterval ->toArray ();
76
152
77
- $ this ->dateTimeInterval -> toArray ( );
153
+ $ this ->assertEquals ( $ expected , $ result );
78
154
}
79
155
80
156
public function test_it_throws_exception_when_creating_array_with_invalid_time_interval ()
0 commit comments