|
2 | 2 |
|
3 | 3 | namespace JMac\Testing\Traits;
|
4 | 4 |
|
| 5 | +use Carbon\CarbonImmutable; |
| 6 | +use Carbon\CarbonInterface; |
| 7 | +use Illuminate\Support\Carbon; |
5 | 8 | use Illuminate\Support\Facades\Route;
|
6 | 9 | use PHPUnit\Framework\Assert as PHPUnitAssert;
|
7 | 10 | use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
|
@@ -109,7 +112,14 @@ public function assertMiddlewareGroupUsesMiddleware(string $middlewareGroup, arr
|
109 | 112 |
|
110 | 113 | $missingMiddlware = array_diff($middlewares, $middlewareGroups[$middlewareGroup]);
|
111 | 114 |
|
112 |
| - PHPUnitAssert::assertTrue(count($missingMiddlware) === 0, "Middlware Group `$middlewareGroup` does not use expected `".implode(', ', $missingMiddlware).'` middleware(s)'); |
| 115 | + PHPUnitAssert::assertTrue(count($missingMiddlware) === 0, "Middleware Group `$middlewareGroup` does not use expected `".implode(', ', $missingMiddlware).'` middleware(s)'); |
| 116 | + } |
| 117 | + |
| 118 | + public function assertNow(CarbonInterface $datetime, ?CarbonInterface $now = null): void |
| 119 | + { |
| 120 | + $now ??= Carbon::now(); |
| 121 | + |
| 122 | + PHPUnitAssert::assertTrue($datetime->equalTo($now), 'Failed asserting that the current time ['.$datetime->toDateTimeString().'] is equal to now ['.$now->toDateTimeString().']'); |
113 | 123 | }
|
114 | 124 |
|
115 | 125 | public function assertRouteUsesFormRequest(string $routeName, string $formRequest): void
|
@@ -191,6 +201,21 @@ public function createFormRequest(string $form_request, array $data = [])
|
191 | 201 | return $form_request::createFromBase(SymfonyRequest::create('', 'POST', $data));
|
192 | 202 | }
|
193 | 203 |
|
| 204 | + public function freezeNow($milliseconds = false): CarbonImmutable |
| 205 | + { |
| 206 | + $now = Carbon::now(); |
| 207 | + |
| 208 | + if (! $milliseconds) { |
| 209 | + $now = $now->startOfSecond(); |
| 210 | + } |
| 211 | + |
| 212 | + $now = $now->toImmutable(); |
| 213 | + |
| 214 | + Carbon::setTestNow($now); |
| 215 | + |
| 216 | + return $now; |
| 217 | + } |
| 218 | + |
194 | 219 | private function expandRules($rule)
|
195 | 220 | {
|
196 | 221 | return is_string($rule) ? explode('|', $rule) : $rule;
|
|
0 commit comments