@@ -28,13 +28,7 @@ class ParserTest extends TestCase
2828
2929 protected function setUp (): void
3030 {
31- $ this ->timezone = ini_get ('date.timezone ' );
32- ini_set ('date.timezone ' , 'Asia/Shanghai ' );
33- }
34-
35- protected function tearDown (): void
36- {
37- ini_set ('date.timezone ' , $ this ->timezone );
31+ $ this ->timezone = 'Asia/Shanghai ' ;
3832 }
3933
4034 public function testIsValid (): void
@@ -60,116 +54,116 @@ public function testParseSecondLevel()
6054 {
6155 $ crontabString = '*/11 * * * * * ' ;
6256 $ parser = new Parser ();
63- $ startTime = Carbon::createFromTimestamp (1561052867 )->startOfMinute ();
64- $ result = $ parser ->parse ($ crontabString , $ startTime ->getTimestamp ());
57+ $ startTime = Carbon::createFromTimestamp (1561052867 , $ this -> timezone )->startOfMinute ();
58+ $ result = $ parser ->parse ($ crontabString , $ startTime ->getTimestamp (), $ this -> timezone );
6559 $ this ->assertSame ([
6660 '2019-06-21 01:47:00 ' ,
6761 '2019-06-21 01:47:11 ' ,
6862 '2019-06-21 01:47:22 ' ,
6963 '2019-06-21 01:47:33 ' ,
7064 '2019-06-21 01:47:44 ' ,
7165 '2019-06-21 01:47:55 ' ,
72- ], $ this ->toDatatime ($ result ));
66+ ], $ this ->toDateTime ($ result ));
7367 /** @var Carbon $last */
7468 $ last = end ($ result );
75- $ result = $ parser ->parse ($ crontabString , $ last ->getTimestamp ());
69+ $ result = $ parser ->parse ($ crontabString , $ last ->getTimestamp (), $ this -> timezone );
7670 $ this ->assertSame ([
7771 '2019-06-21 01:47:55 ' ,
7872 '2019-06-21 01:48:06 ' ,
7973 '2019-06-21 01:48:17 ' ,
8074 '2019-06-21 01:48:28 ' ,
8175 '2019-06-21 01:48:39 ' ,
8276 '2019-06-21 01:48:50 ' ,
83- ], $ this ->toDatatime ($ result ));
77+ ], $ this ->toDateTime ($ result ));
8478 }
8579
8680 public function testParseSecondLevelBetween (): void
8781 {
8882 $ crontabString = '10-15/1 * * * * * ' ;
8983 $ parser = new Parser ();
90- $ startTime = Carbon::createFromTimestamp (1591754280 )->startOfMinute ();
91- $ result = $ parser ->parse ($ crontabString , $ startTime ->getTimestamp ());
84+ $ startTime = Carbon::createFromTimestamp (1591754280 , $ this -> timezone )->startOfMinute ();
85+ $ result = $ parser ->parse ($ crontabString , $ startTime ->getTimestamp (), $ this -> timezone );
9286 $ this ->assertSame ([
9387 '2020-06-10 09:58:10 ' ,
9488 '2020-06-10 09:58:11 ' ,
9589 '2020-06-10 09:58:12 ' ,
9690 '2020-06-10 09:58:13 ' ,
9791 '2020-06-10 09:58:14 ' ,
9892 '2020-06-10 09:58:15 ' ,
99- ], $ this ->toDatatime ($ result ));
93+ ], $ this ->toDateTime ($ result ));
10094 }
10195
10296 public function testParseSecondLevelForComma (): void
10397 {
10498 $ crontabString = '10-12/1,14-15/1 * * * * * ' ;
10599 $ parser = new Parser ();
106- $ startTime = Carbon::createFromTimestamp (1591754280 )->startOfMinute ();
107- $ result = $ parser ->parse ($ crontabString , $ startTime ->getTimestamp ());
100+ $ startTime = Carbon::createFromTimestamp (1591754280 , $ this -> timezone )->startOfMinute ();
101+ $ result = $ parser ->parse ($ crontabString , $ startTime ->getTimestamp (), $ this -> timezone );
108102 $ this ->assertSame ([
109103 '2020-06-10 09:58:10 ' ,
110104 '2020-06-10 09:58:11 ' ,
111105 '2020-06-10 09:58:12 ' ,
112106 '2020-06-10 09:58:14 ' ,
113107 '2020-06-10 09:58:15 ' ,
114- ], $ this ->toDatatime ($ result ));
108+ ], $ this ->toDateTime ($ result ));
115109 }
116110
117111 public function testParseSecondLevelWithoutBackslash (): void
118112 {
119113 $ crontabString = '10-12,14-15/1 * * * * * ' ;
120114 $ parser = new Parser ();
121- $ startTime = Carbon::createFromTimestamp (1591754280 )->startOfMinute ();
122- $ result = $ parser ->parse ($ crontabString , $ startTime ->getTimestamp ());
115+ $ startTime = Carbon::createFromTimestamp (1591754280 , $ this -> timezone )->startOfMinute ();
116+ $ result = $ parser ->parse ($ crontabString , $ startTime ->getTimestamp (), $ this -> timezone );
123117 $ this ->assertSame ([
124118 '2020-06-10 09:58:10 ' ,
125119 '2020-06-10 09:58:11 ' ,
126120 '2020-06-10 09:58:12 ' ,
127121 '2020-06-10 09:58:14 ' ,
128122 '2020-06-10 09:58:15 ' ,
129- ], $ this ->toDatatime ($ result ));
123+ ], $ this ->toDateTime ($ result ));
130124 }
131125
132126 public function testParseSecondLevelWithEmptyString ()
133127 {
134128 $ crontabString = '10,14,,15, * * * * * ' ;
135129 $ parser = new Parser ();
136- $ startTime = Carbon::createFromTimestamp (1591754280 )->startOfMinute ();
137- $ result = $ parser ->parse ($ crontabString , $ startTime ->getTimestamp ());
130+ $ startTime = Carbon::createFromTimestamp (1591754280 , $ this -> timezone )->startOfMinute ();
131+ $ result = $ parser ->parse ($ crontabString , $ startTime ->getTimestamp (), $ this -> timezone );
138132 $ this ->assertSame ([
139133 '2020-06-10 09:58:10 ' ,
140134 '2020-06-10 09:58:14 ' ,
141135 '2020-06-10 09:58:15 ' ,
142- ], $ this ->toDatatime ($ result ));
136+ ], $ this ->toDateTime ($ result ));
143137 }
144138
145139 public function testParseMinuteLevelBetween (): void
146140 {
147141 $ crontabString = '10-15/1 10-12/1 10 * * * ' ;
148142 $ parser = new Parser ();
149- $ startTime = Carbon::createFromTimestamp (1591755010 )->startOfMinute ();
150- $ result = $ parser ->parse ($ crontabString , $ startTime ->getTimestamp ());
143+ $ startTime = Carbon::createFromTimestamp (1591755010 , $ this -> timezone )->startOfMinute ();
144+ $ result = $ parser ->parse ($ crontabString , $ startTime ->getTimestamp (), $ this -> timezone );
151145 $ this ->assertSame ([
152146 '2020-06-10 10:10:10 ' ,
153147 '2020-06-10 10:10:11 ' ,
154148 '2020-06-10 10:10:12 ' ,
155149 '2020-06-10 10:10:13 ' ,
156150 '2020-06-10 10:10:14 ' ,
157151 '2020-06-10 10:10:15 ' ,
158- ], $ this ->toDatatime ($ result ));
152+ ], $ this ->toDateTime ($ result ));
159153
160154 $ last = end ($ result );
161- $ result = $ parser ->parse ($ crontabString , $ last ->addMinute ()->startOfMinute ());
155+ $ result = $ parser ->parse ($ crontabString , $ last ->addMinute ()->startOfMinute (), $ this -> timezone );
162156 $ this ->assertSame ([
163157 '2020-06-10 10:11:10 ' ,
164158 '2020-06-10 10:11:11 ' ,
165159 '2020-06-10 10:11:12 ' ,
166160 '2020-06-10 10:11:13 ' ,
167161 '2020-06-10 10:11:14 ' ,
168162 '2020-06-10 10:11:15 ' ,
169- ], $ this ->toDatatime ($ result ));
163+ ], $ this ->toDateTime ($ result ));
170164
171165 $ last = end ($ result );
172- $ result = $ parser ->parse ($ crontabString , $ last ->addMinute ()->startOfMinute ());
166+ $ result = $ parser ->parse ($ crontabString , $ last ->addMinute ()->startOfMinute (), $ this -> timezone );
173167
174168 $ this ->assertSame ([
175169 '2020-06-10 10:12:10 ' ,
@@ -178,59 +172,59 @@ public function testParseMinuteLevelBetween(): void
178172 '2020-06-10 10:12:13 ' ,
179173 '2020-06-10 10:12:14 ' ,
180174 '2020-06-10 10:12:15 ' ,
181- ], $ this ->toDatatime ($ result ));
175+ ], $ this ->toDateTime ($ result ));
182176
183177 $ last = end ($ result );
184- $ result = $ parser ->parse ($ crontabString , $ last ->addMinute ()->startOfMinute ());
178+ $ result = $ parser ->parse ($ crontabString , $ last ->addMinute ()->startOfMinute (), $ this -> timezone );
185179
186- $ this ->assertSame ([], $ this ->toDatatime ($ result ));
180+ $ this ->assertSame ([], $ this ->toDateTime ($ result ));
187181 }
188182
189183 public function testParseSecondLevelWithCarbonStartTime ()
190184 {
191185 $ crontabString = '*/11 * * * * * ' ;
192186 $ parser = new Parser ();
193- $ startTime = Carbon::createFromTimestamp (1561052867 )->startOfMinute ();
194- $ result = $ parser ->parse ($ crontabString , $ startTime );
187+ $ startTime = Carbon::createFromTimestamp (1561052867 , $ this -> timezone )->startOfMinute ();
188+ $ result = $ parser ->parse ($ crontabString , $ startTime, $ this -> timezone );
195189 $ this ->assertSame ([
196190 '2019-06-21 01:47:00 ' ,
197191 '2019-06-21 01:47:11 ' ,
198192 '2019-06-21 01:47:22 ' ,
199193 '2019-06-21 01:47:33 ' ,
200194 '2019-06-21 01:47:44 ' ,
201195 '2019-06-21 01:47:55 ' ,
202- ], $ this ->toDatatime ($ result ));
196+ ], $ this ->toDateTime ($ result ));
203197 /** @var Carbon $last */
204198 $ last = end ($ result );
205- $ result = $ parser ->parse ($ crontabString , $ last );
199+ $ result = $ parser ->parse ($ crontabString , $ last, $ this -> timezone );
206200 $ this ->assertSame ([
207201 '2019-06-21 01:47:55 ' ,
208202 '2019-06-21 01:48:06 ' ,
209203 '2019-06-21 01:48:17 ' ,
210204 '2019-06-21 01:48:28 ' ,
211205 '2019-06-21 01:48:39 ' ,
212206 '2019-06-21 01:48:50 ' ,
213- ], $ this ->toDatatime ($ result ));
207+ ], $ this ->toDateTime ($ result ));
214208 }
215209
216210 public function testParseMinuteLevel ()
217211 {
218212 $ crontabString = '*/11 * * * * ' ;
219213 $ parser = new Parser ();
220- $ startTime = Carbon::createFromTimestamp (1561052867 )->startOfMinute ();
221- $ result = $ parser ->parse ($ crontabString , $ startTime ->getTimestamp ());
222- $ this ->assertSame ([], $ this ->toDatatime ($ result ));
214+ $ startTime = Carbon::createFromTimestamp (1561052867 , $ this -> timezone )->startOfMinute ();
215+ $ result = $ parser ->parse ($ crontabString , $ startTime ->getTimestamp (), $ this -> timezone );
216+ $ this ->assertSame ([], $ this ->toDateTime ($ result ));
223217
224218 $ startTime ->minute (33 );
225- $ result = $ parser ->parse ($ crontabString , $ startTime ->getTimestamp ());
226- $ this ->assertSame (['2019-06-21 01:33:00 ' ], $ this ->toDatatime ($ result ));
219+ $ result = $ parser ->parse ($ crontabString , $ startTime ->getTimestamp (), $ this -> timezone );
220+ $ this ->assertSame (['2019-06-21 01:33:00 ' ], $ this ->toDateTime ($ result ));
227221 }
228222
229223 /**
230224 * @param Carbon[] $result
231225 * @return string[]
232226 */
233- protected function toDatatime (array $ result )
227+ protected function toDateTime (array $ result )
234228 {
235229 $ dates = [];
236230 foreach ($ result as $ date ) {
0 commit comments