@@ -32,6 +32,35 @@ public function test_it_creates_a_new_instance()
3232 $ this ->assertInstanceOf (DateTimeInterval::class, $ DeepLinkResources );
3333 }
3434
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+
3564 public function test_it_gets_start ()
3665 {
3766 $ result = $ this ->dateTimeInterval ->getStart ();
@@ -66,15 +95,62 @@ public function test_it_sets_end()
6695 $ this ->assertEquals ($ expected , $ this ->dateTimeInterval ->getEnd ());
6796 }
6897
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 ()
70130 {
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+
71148 $ this ->dateTimeInterval ->setStart (null );
72149 $ this ->dateTimeInterval ->setEnd (null );
73150
74- $ this ->expectException (LtiException::class);
75- $ this ->expectExceptionMessage (DateTimeInterval::ERROR_NO_START_OR_END );
151+ $ result = $ this ->dateTimeInterval ->toArray ();
76152
77- $ this ->dateTimeInterval -> toArray ( );
153+ $ this ->assertEquals ( $ expected , $ result );
78154 }
79155
80156 public function test_it_throws_exception_when_creating_array_with_invalid_time_interval ()
0 commit comments