startOfSecond(); $this->travelTo($now); $expiresAt = $now->copy()->addMinutes(12); $resource = $this->resourceFor(Purchase::STATUS_PENDING_PAYMENT, $expiresAt); $this->assertTrue($expiresAt->equalTo($resource['expires_at'])); $this->assertSame(720, $resource['expires_in_seconds']); $this->assertTrue($now->equalTo($resource['server_time'])); $this->travelBack(); } public function test_it_clamps_an_overdue_checkout_to_zero_seconds(): void { $now = now()->startOfSecond(); $this->travelTo($now); $resource = $this->resourceFor( Purchase::STATUS_CREATED, $now->copy()->subSecond(), ); $this->assertSame(0, $resource['expires_in_seconds']); $this->travelBack(); } public function test_it_exposes_null_expiration_after_the_purchase_enters_review(): void { $resource = $this->resourceFor( Purchase::STATUS_IN_REVIEW, null, ); $this->assertNull($resource['expires_at']); $this->assertNull($resource['expires_in_seconds']); } /** @return array */ private function resourceFor(string $status, ?Carbon $expiresAt): array { $purchase = (new Purchase)->forceFill([ 'status' => $status, 'total' => '0.00', ]); $purchase->setRelation('stockReservation', (new StockReservation)->forceFill([ 'status' => StockReservation::STATUS_ACTIVE, 'expires_at' => $expiresAt, ])); return (new PurchaseResource($purchase))->toArray(Request::create('/')); } }