No flags found
Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.
e.g., #unittest #integration
#production #enterprise
#frontend #backend
c37370b
... +0 ...
35a688b
Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.
e.g., #unittest #integration
#production #enterprise
#frontend #backend
12 | 12 | namespace Carbon\Traits; |
|
13 | 13 | ||
14 | 14 | use Carbon\CarbonInterface; |
|
15 | + | use Carbon\CarbonTimeZone; |
|
15 | 16 | use Closure; |
|
16 | 17 | use DateTimeImmutable; |
|
17 | 18 | use DateTimeInterface; |
|
19 | + | use InvalidArgumentException; |
|
20 | + | use Throwable; |
|
18 | 21 | ||
19 | 22 | trait Test |
|
20 | 23 | { |
84 | 87 | $useDateInstanceTimezone = $testNow instanceof DateTimeInterface; |
|
85 | 88 | ||
86 | 89 | if ($useDateInstanceTimezone) { |
|
87 | - | date_default_timezone_set($testNow->getTimezone()->getName()); |
|
90 | + | self::setDefaultTimezone($testNow->getTimezone()->getName(), $testNow); |
|
88 | 91 | } |
|
89 | 92 | ||
90 | 93 | static::setTestNow($testNow); |
|
91 | 94 | ||
92 | 95 | if (!$useDateInstanceTimezone) { |
|
93 | - | date_default_timezone_set(static::getMockedTestNow(\func_num_args() === 1 ? null : $tz)->timezone); |
|
96 | + | $now = static::getMockedTestNow(\func_num_args() === 1 ? null : $tz); |
|
97 | + | self::setDefaultTimezone($now->tzName, $now); |
|
94 | 98 | } |
|
95 | 99 | } |
|
96 | 100 |
175 | 179 | ? $testInstance->rawFormat(static::MOCK_DATETIME_FORMAT) |
|
176 | 180 | : $testInstance->format(static::MOCK_DATETIME_FORMAT); |
|
177 | 181 | } |
|
182 | + | ||
183 | + | private static function setDefaultTimezone($timezone, DateTimeInterface $date = null) |
|
184 | + | { |
|
185 | + | $previous = null; |
|
186 | + | $success = false; |
|
187 | + | ||
188 | + | try { |
|
189 | + | $success = date_default_timezone_set($timezone); |
|
190 | + | } catch (Throwable $exception) { |
|
191 | + | $previous = $exception; |
|
192 | + | } |
|
193 | + | ||
194 | + | if (!$success) { |
|
195 | + | $suggestion = @CarbonTimeZone::create($timezone)->toRegionName($date); |
|
196 | + | ||
197 | + | throw new InvalidArgumentException( |
|
198 | + | "Timezone ID '$timezone' is invalid". |
|
199 | + | ($suggestion && $suggestion !== $timezone ? ", did you mean '$suggestion'?" : '.')."\n". |
|
200 | + | "It must be one of the IDs from DateTimeZone::listIdentifiers(),\n". |
|
201 | + | 'For the record, hours/minutes offset are relevant only for a particular moment, '. |
|
202 | + | 'but not as a default timezone.', |
|
203 | + | 0, |
|
204 | + | $previous |
|
205 | + | ); |
|
206 | + | } |
|
207 | + | } |
|
178 | 208 | } |
Files | Complexity | Coverage |
---|---|---|
Carbon | ø | 100.00% |
Project Totals (886 files) | 2158 | 100.00% |
#2501
35a688b
c37370b