File tree 1 file changed +65
-0
lines changed
1 file changed +65
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Setono \PeakWMS \DataTransferObject ;
6
+
7
+ use PHPUnit \Framework \TestCase ;
8
+
9
+ final class AbstractDataTransferObjectTest extends TestCase
10
+ {
11
+ /**
12
+ * @test
13
+ */
14
+ public function it_converts_date_time (): void
15
+ {
16
+ $ dt = AbstractDataTransferObjectTestDummy::convertDateTime ('2024-12-04T12:35:29+02:00 ' );
17
+
18
+ self ::assertSame ('2024-12-04T12:35:29+02:00 ' , $ dt ->format (\DATE_ATOM ));
19
+ }
20
+
21
+ /**
22
+ * @test
23
+ */
24
+ public function it_returns_null_if_input_is_null (): void
25
+ {
26
+ $ dt = AbstractDataTransferObjectTestDummy::convertDateTime (null );
27
+
28
+ self ::assertNull ($ dt );
29
+ }
30
+
31
+ /**
32
+ * @test
33
+ */
34
+ public function it_returns_same_object_if_input_is_date_time (): void
35
+ {
36
+ $ dt1 = new \DateTimeImmutable ('2024-12-04T12:35:29+02:00 ' );
37
+ $ dt2 = AbstractDataTransferObjectTestDummy::convertDateTime ($ dt1 );
38
+
39
+ self ::assertSame ($ dt1 , $ dt2 );
40
+ }
41
+
42
+ /**
43
+ * @test
44
+ */
45
+ public function it_returns_date_time_immutable_if_input_is_not (): void
46
+ {
47
+ $ dt1 = new \DateTime ('2024-12-04T12:35:29+02:00 ' );
48
+ $ dt2 = AbstractDataTransferObjectTestDummy::convertDateTime ($ dt1 );
49
+
50
+ self ::assertSame ('2024-12-04T12:35:29+02:00 ' , $ dt2 ->format (\DATE_ATOM ));
51
+ }
52
+
53
+ /**
54
+ * @test
55
+ */
56
+ public function it_throws_if_input_cannot_be_converted (): void
57
+ {
58
+ $ this ->expectException (\InvalidArgumentException::class);
59
+ AbstractDataTransferObjectTestDummy::convertDateTime ('2024-12-04T12:35:29.123456+02:00 ' );
60
+ }
61
+ }
62
+
63
+ final class AbstractDataTransferObjectTestDummy extends AbstractDataTransferObject
64
+ {
65
+ }
You can’t perform that action at this time.
0 commit comments