6
6
7
7
use Closure ;
8
8
use DateTime ;
9
+ use DateTimeImmutable ;
9
10
use DateTimeInterface ;
10
11
use PHPUnit \Framework \TestCase ;
11
12
use WrkFlow \ApiSdkBuilder \Log \Entities \LoggerConfigEntity ;
@@ -20,6 +21,63 @@ protected function setUp(): void
20
21
$ this ->fileLogPathService = new FileLogPathService ();
21
22
}
22
23
24
+ public function dataIsRootDirectory (): array
25
+ {
26
+ return [
27
+ ['2023-03-20 ' , true ],
28
+ ['2022-12-10 ' , true ],
29
+ ['2022-12-01 ' , true ],
30
+ ['0000-00-00 ' , true ],
31
+ ['2022-12- ' , false ],
32
+ ['2022-12-204 ' , false ],
33
+ ['test ' , false ],
34
+ ['my-directory ' , false ],
35
+ ['00-00-00 ' , false ],
36
+ ['01 ' , false ],
37
+ ['' , false ],
38
+ ];
39
+ }
40
+
41
+
42
+ /**
43
+ * @dataProvider dataIsRootDirectory
44
+ */
45
+ public function testIsRootDirectory (string $ directory , bool $ expected ): void
46
+ {
47
+ $ this ->assertEquals (expected: $ expected , actual: $ this ->fileLogPathService ->isRootDirectory ($ directory ));
48
+ }
49
+
50
+ public function dataGetRootDirectoryName (): array
51
+ {
52
+ return [
53
+ ['2022-12-10T00:30:00-03:00 ' , '2022-12-10 ' ],
54
+ ['2022-12-10T00:30:00+03:00 ' , '2022-12-09 ' ],
55
+ ['2022-12-10T00:30:00+00:00 ' , '2022-12-10 ' ],
56
+ ['2022-12-10T23:30:00+01:00 ' , '2022-12-10 ' ],
57
+ ['2022-12-10T23:30:00+02:00 ' , '2022-12-10 ' ],
58
+ ['2022-12-10T23:30:00+03:00 ' , '2022-12-10 ' ],
59
+ ['2022-12-10T23:30:00+04:00 ' , '2022-12-10 ' ],
60
+ ['2022-12-10T23:30:00-01:00 ' , '2022-12-11 ' ],
61
+ ['2022-12-10T23:30:00-02:00 ' , '2022-12-11 ' ],
62
+ ['2022-12-10T23:30:00-03:00 ' , '2022-12-11 ' ],
63
+ ['2022-12-10T23:30:00-04:00 ' , '2022-12-11 ' ],
64
+ ];
65
+ }
66
+
67
+
68
+ /**
69
+ * @dataProvider dataGetRootDirectoryName
70
+ */
71
+ public function testGetRootDirectoryName (string $ date , string $ expected ): void
72
+ {
73
+ date_default_timezone_set ('Europe/Prague ' );
74
+
75
+ $ this ->assertEquals (
76
+ expected: $ expected ,
77
+ actual: $ this ->fileLogPathService ->getRootDirectoryName (new DateTimeImmutable ($ date ))
78
+ );
79
+ }
80
+
23
81
/**
24
82
* @return array<string|int, array{0: Closure(static):void}>
25
83
*/
0 commit comments