output:
Chunk ID: 67c76c
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 6952
Output:
tests/Feature/Analytics/AnalyticsServiceTest.php:20:    return Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Analytics/AnalyticsServiceTest.php:76:        ->firstOrFail();
tests/Feature/Admin/CustomerManagementTest.php:23:    $store = Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Admin/CustomerManagementTest.php:31:    return User::query()->where('email', 'admin@acme.test')->firstOrFail();
tests/Feature/Admin/CustomerManagementTest.php:134:        ->firstOrFail();
tests/Browser/Admin/CustomerManagementTest.php:39:    $store = Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Browser/Admin/CustomerManagementTest.php:40:    $user = User::query()->where('email', 'admin@acme.test')->firstOrFail();
tests/Browser/Admin/CustomerManagementTest.php:53:        ->firstOrFail();
tests/Browser/Admin/CustomerManagementTest.php:61:        ->firstOrFail();
tests/Browser/Admin/CustomerManagementTest.php:64:        ->firstOrFail();
tests/Browser/Admin/CustomerManagementTest.php:71:        'order_number' => '#1001',
tests/Browser/Admin/CustomerManagementTest.php:150:        ->assertSee('#1001')
tests/Browser/Admin/CollectionManagementTest.php:29:    return Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Browser/Admin/CollectionManagementTest.php:35:    $user = User::query()->where('email', 'admin@acme.test')->firstOrFail();
tests/Browser/Admin/CollectionManagementTest.php:116:        ->firstOrFail();
tests/Feature/DashboardTest.php:16:    $user = User::query()->where('email', 'admin@acme.test')->firstOrFail();
tests/Feature/Orders/OrderServiceTest.php:64:        ->firstOrFail();
tests/Feature/Orders/OrderServiceTest.php:161:    expect($order->order_number)->toBe('#1001')
tests/Feature/Orders/OrderServiceTest.php:179:    $inventory = InventoryItem::withoutGlobalScopes()->where('variant_id', $variant->getKey())->firstOrFail();
tests/Feature/Orders/OrderServiceTest.php:262:        ->and(Order::withoutGlobalScopes()->count())->toBe(1)
tests/Feature/Orders/OrderServiceTest.php:281:    $inventory = InventoryItem::withoutGlobalScopes()->where('variant_id', $variant->getKey())->firstOrFail();
tests/Feature/Orders/OrderServiceTest.php:298:    $inventory = InventoryItem::withoutGlobalScopes()->where('variant_id', $variant->getKey())->firstOrFail();
tests/Feature/Orders/OrderServiceTest.php:300:    expect(Order::withoutGlobalScopes()->count())->toBe(0)
tests/Feature/Admin/OrderManagementTest.php:33:    $store = Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Admin/OrderManagementTest.php:41:    return User::query()->where('email', 'admin@acme.test')->firstOrFail();
tests/Feature/Admin/OrderManagementTest.php:54:        ->firstOrFail();
tests/Feature/Admin/OrderManagementTest.php:170:    $inventory = InventoryItem::withoutGlobalScopes()->where('variant_id', $variant->getKey())->firstOrFail();
tests/Feature/Admin/OrderManagementTest.php:202:    $fulfillment = Fulfillment::query()->where('order_id', $order->getKey())->firstOrFail();
tests/Feature/Checkout/PricingServicesTest.php:57:        ->firstOrFail();
tests/Feature/Checkout/PricingServicesTest.php:170:    $line = $checkout->cart->lines()->firstOrFail();
tests/Feature/Checkout/PricingServicesTest.php:198:    $line = $checkout->cart->lines()->firstOrFail();
tests/Feature/Admin/AppsDevelopersTest.php:24:    return Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Browser/Admin/SettingsTest.php:31:    return Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Browser/Admin/SettingsTest.php:37:    $user = User::query()->where('email', 'admin@acme.test')->firstOrFail();
tests/Browser/Admin/SettingsTest.php:128:        ->firstOrFail();
tests/Browser/Admin/SettingsTest.php:133:        ->firstOrFail();
tests/Browser/Admin/SettingsTest.php:155:    $settings = TaxSettings::withoutGlobalScopes()->whereKey($store->getKey())->firstOrFail();
tests/Feature/Api/StorefrontCheckoutApiTest.php:22:    return Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Api/StorefrontCheckoutApiTest.php:30:        ->firstOrFail();
tests/Feature/Api/StorefrontCheckoutApiTest.php:35:        ->firstOrFail();
tests/Feature/Api/StorefrontCheckoutApiTest.php:138:    $inventory = InventoryItem::withoutGlobalScopes()->where('variant_id', $variant->getKey())->firstOrFail();
tests/Feature/Api/StorefrontCheckoutApiTest.php:181:        ->whereHas('zone', fn ($query) => $query->withoutGlobalScopes()->where('store_id', Store::query()->whereKeyNot($store->getKey())->firstOrFail()->getKey()))
tests/Feature/Api/StorefrontCheckoutApiTest.php:182:        ->firstOrFail();
tests/Feature/Admin/AnalyticsDashboardTest.php:21:    return Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Orders/BankTransferOrderTest.php:40:    $variant = ProductVariant::withoutGlobalScopes()->where('product_id', $product->getKey())->firstOrFail();
tests/Feature/Orders/BankTransferOrderTest.php:86:    $inventory = InventoryItem::withoutGlobalScopes()->where('variant_id', $variant->getKey())->firstOrFail();
tests/Feature/Orders/BankTransferOrderTest.php:116:    $oldInventory = InventoryItem::withoutGlobalScopes()->where('variant_id', $oldVariant->getKey())->firstOrFail();
tests/Feature/Orders/BankTransferOrderTest.php:117:    $newInventory = InventoryItem::withoutGlobalScopes()->where('variant_id', $newVariant->getKey())->firstOrFail();
tests/Feature/Search/SearchServiceTest.php:21:    return Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Search/SearchServiceTest.php:26:    $otherStore = Store::query()->whereKeyNot($store->getKey())->firstOrFail();
tests/Feature/Search/SearchServiceTest.php:53:    $queryLog = SearchQuery::withoutGlobalScopes()->where('store_id', $store->getKey())->latest('id')->firstOrFail();
tests/Browser/Admin/AnalyticsTest.php:28:    $store = Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Browser/Admin/AnalyticsTest.php:29:    $user = User::query()->where('email', 'admin@acme.test')->firstOrFail();
tests/Feature/Admin/ContentManagementTest.php:33:    $store = Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Admin/ContentManagementTest.php:41:    return User::query()->where('email', 'admin@acme.test')->firstOrFail();
tests/Feature/Admin/ContentManagementTest.php:62:    $theme = Theme::withoutGlobalScopes()->where('store_id', $store->getKey())->firstOrFail();
tests/Feature/Admin/ContentManagementTest.php:114:        ->firstOrFail();
tests/Feature/Admin/ContentManagementTest.php:149:        ->firstOrFail();
tests/Feature/Admin/ContentManagementTest.php:204:    $published = Theme::withoutGlobalScopes()->where('store_id', $store->getKey())->firstOrFail();
tests/Feature/Admin/ContentManagementTest.php:214:        ->firstOrFail();
tests/Feature/Admin/ContentManagementTest.php:215:    $publishedFile = $published->files()->withoutGlobalScopes()->firstOrFail();
tests/Feature/Admin/ContentManagementTest.php:216:    $copyFile = $copy->files()->withoutGlobalScopes()->where('path', $publishedFile->path)->firstOrFail();
tests/Feature/Admin/ContentManagementTest.php:237:    $theme = Theme::withoutGlobalScopes()->where('store_id', $store->getKey())->firstOrFail();
tests/Feature/Admin/ContentManagementTest.php:238:    $file = $theme->files()->withoutGlobalScopes()->where('path', 'sections/hero.blade.php')->firstOrFail();
tests/Feature/Admin/ContentManagementTest.php:264:    $theme = Theme::withoutGlobalScopes()->where('store_id', $store->getKey())->firstOrFail();
tests/Feature/Checkout/CheckoutServiceTest.php:44:        ->firstOrFail();
tests/Feature/Api/StorefrontSearchApiTest.php:19:    return Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Api/StorefrontSearchApiTest.php:24:    $otherStore = Store::query()->whereKeyNot($store->getKey())->firstOrFail();
tests/Feature/Api/AdminDiscountApiTest.php:22:    return Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Api/AdminDiscountApiTest.php:27:    return User::query()->where('email', 'admin@acme.test')->firstOrFail();
tests/Feature/Catalog/ProductServiceTest.php:102:    $variant = $product->variants()->firstOrFail();
tests/Browser/Admin/OrderManagementTest.php:42:    $store = Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Browser/Admin/OrderManagementTest.php:43:    $user = User::query()->where('email', 'admin@acme.test')->firstOrFail();
tests/Browser/Admin/OrderManagementTest.php:54:    $store = Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Browser/Admin/OrderManagementTest.php:55:    $customer = Customer::query()->where('email', 'customer@acme.test')->firstOrFail();
tests/Browser/Admin/OrderManagementTest.php:59:        ->firstOrFail();
tests/Browser/Admin/OrderManagementTest.php:62:        ->firstOrFail();
tests/Browser/Admin/OrderManagementTest.php:69:        orderNumber: '#1001',
tests/Browser/Admin/OrderManagementTest.php:82:        orderNumber: '#1002',
tests/Browser/Admin/OrderManagementTest.php:97:        orderNumber: '#1005',
tests/Browser/Admin/OrderManagementTest.php:179:    $line = $order->lines()->firstOrFail();
tests/Browser/Admin/OrderManagementTest.php:234:        ->assertSee('#1001')
tests/Browser/Admin/OrderManagementTest.php:242:        ->assertSee('#1001')
tests/Browser/Admin/OrderManagementTest.php:243:        ->assertDontSee('#1005')
tests/Browser/Admin/OrderManagementTest.php:247:        ->assertSee('#1002')
tests/Browser/Admin/OrderManagementTest.php:252:        ->assertSee('#1001')
tests/Browser/Admin/OrderManagementTest.php:253:        ->assertSee('#1005')
tests/Browser/Admin/OrderManagementTest.php:258:    adminOrderOpenOrder($this, '#1001')
tests/Browser/Admin/OrderManagementTest.php:270:    adminOrderOpenOrder($this, '#1001')
tests/Browser/Admin/OrderManagementTest.php:277:    adminOrderCreateFulfillmentInBrowser(adminOrderOpenOrder($this, '#1001'));
tests/Browser/Admin/OrderManagementTest.php:281:    adminOrderOpenOrder($this, '#1001')
tests/Browser/Admin/OrderManagementTest.php:294:    adminOrderOpenOrder($this, '#1001')
tests/Browser/Admin/OrderManagementTest.php:300:    adminOrderOpenOrder($this, '#1005')
tests/Browser/Admin/OrderManagementTest.php:312:    adminOrderOpenOrder($this, '#1005')
tests/Browser/Admin/OrderManagementTest.php:320:    $page = adminOrderCreateFulfillmentInBrowser(adminOrderOpenOrder($this, '#1001'));
tests/Browser/Admin/OrderManagementTest.php:329:    $page = adminOrderCreateFulfillmentInBrowser(adminOrderOpenOrder($this, '#1001'));
tests/Feature/Admin/DiscountManagementTest.php:30:    $store = Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Admin/DiscountManagementTest.php:38:    return User::query()->where('email', 'admin@acme.test')->firstOrFail();
tests/Feature/Admin/DiscountManagementTest.php:154:    $product = Product::withoutGlobalScopes()->where('store_id', $store->getKey())->firstOrFail();
tests/Feature/Admin/DiscountManagementTest.php:155:    $collection = Collection::withoutGlobalScopes()->where('store_id', $store->getKey())->firstOrFail();
tests/Feature/Admin/DiscountManagementTest.php:174:        ->firstOrFail();
tests/Feature/Admin/DiscountManagementTest.php:252:        ->firstOrFail();
tests/Browser/Admin/PageManagementTest.php:29:    $store = Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Browser/Admin/PageManagementTest.php:30:    $user = User::query()->where('email', 'admin@acme.test')->firstOrFail();
tests/Browser/Admin/PageManagementTest.php:93:        ->firstOrFail();
tests/Browser/Storefront/TenantIsolationTest.php:29:    return Store::query()->where('handle', $handle)->firstOrFail();
tests/Browser/Storefront/TenantIsolationTest.php:39:        ->firstOrFail();
tests/Browser/Storefront/TenantIsolationTest.php:54:    foreach (['#1001', '#1002', '#1004'] as $orderNumber) {
tests/Browser/Storefront/TenantIsolationTest.php:133:        ->assertSee('#1001')
tests/Browser/Storefront/TenantIsolationTest.php:157:        ->assertSee('#1001')
tests/Browser/Storefront/TenantIsolationTest.php:158:        ->assertSee('#1002')
tests/Browser/Storefront/TenantIsolationTest.php:159:        ->assertSee('#1004')
tests/Feature/Api/AdminThemeApiTest.php:24:    return Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Api/AdminThemeApiTest.php:29:    return User::query()->where('email', 'admin@acme.test')->firstOrFail();
tests/Feature/Api/AdminThemeApiTest.php:121:    $hero = $theme->files()->withoutGlobalScopes()->where('path', 'sections/hero.blade.php')->firstOrFail();
tests/Feature/Api/AdminThemeApiTest.php:129:    $published = Theme::withoutGlobalScopes()->where('store_id', $store->getKey())->where('status', ThemeStatus::Published)->firstOrFail();
tests/Feature/Api/AdminCatalogApiTest.php:23:    return Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Api/AdminCatalogApiTest.php:28:    return User::query()->where('email', 'admin@acme.test')->firstOrFail();
tests/Feature/Api/AdminCatalogApiTest.php:53:        ->firstOrFail();
tests/Feature/Api/AdminSearchIndexApiTest.php:22:    return Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Api/AdminSearchIndexApiTest.php:27:    return User::query()->where('email', 'admin@acme.test')->firstOrFail();
tests/Feature/Api/AdminSearchIndexApiTest.php:66:        ->and(SearchSettings::withoutGlobalScopes()->where('store_id', $store->getKey())->firstOrFail()->updated_at)->not->toBeNull();
tests/Feature/Orders/RefundServiceTest.php:35:        ->firstOrFail();
tests/Feature/Admin/ProductMediaManagementTest.php:53:        ->firstOrFail();
tests/Feature/Admin/ProductMediaManagementTest.php:93:        ->firstOrFail();
tests/Feature/Admin/ProductMediaManagementTest.php:96:        ->firstOrFail();
tests/Feature/Foundation/TenancyTest.php:52:    $user = User::query()->where('email', 'admin@acme.test')->firstOrFail();
tests/Feature/Foundation/TenancyTest.php:53:    $store = Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Api/AdminOrderExportApiTest.php:23:    return Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Api/AdminOrderExportApiTest.php:28:    return User::query()->where('email', 'admin@acme.test')->firstOrFail();
tests/Feature/Orders/FulfillmentServiceTest.php:32:    $firstVariant = ProductVariant::withoutGlobalScopes()->where('product_id', $firstProduct->getKey())->firstOrFail();
tests/Feature/Orders/FulfillmentServiceTest.php:33:    $secondVariant = ProductVariant::withoutGlobalScopes()->where('product_id', $secondProduct->getKey())->firstOrFail();
tests/Feature/Api/AdminAnalyticsSummaryApiTest.php:23:    return Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Api/AdminAnalyticsSummaryApiTest.php:28:    return User::query()->where('email', 'admin@acme.test')->firstOrFail();
tests/Browser/Admin/DiscountManagementTest.php:28:    return Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Browser/Admin/DiscountManagementTest.php:34:    $user = User::query()->where('email', 'admin@acme.test')->firstOrFail();
tests/Feature/Api/StorefrontAnalyticsApiTest.php:16:    $store = Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Browser/Admin/ProductManagementTest.php:28:    $store = Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Browser/Admin/ProductManagementTest.php:29:    $user = User::query()->where('email', 'admin@acme.test')->firstOrFail();
tests/Feature/Catalog/InventoryServiceTest.php:18:    $item = $variant->inventoryItem()->firstOrFail();
tests/Feature/Catalog/InventoryServiceTest.php:43:    $denyItem = $denyVariant->inventoryItem()->firstOrFail();
tests/Feature/Catalog/InventoryServiceTest.php:51:    $continueItem = $continueVariant->inventoryItem()->firstOrFail();
tests/Feature/Admin/DashboardTest.php:23:    $store = Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Admin/DashboardTest.php:31:    return User::query()->where('email', 'admin@acme.test')->firstOrFail();
tests/Feature/Admin/DashboardTest.php:44:        ->firstOrFail();
tests/Feature/Api/StorefrontOrderApiTest.php:21:    return Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Api/StorefrontOrderApiTest.php:29:        ->firstOrFail();
tests/Feature/Api/StorefrontOrderApiTest.php:34:        ->firstOrFail();
tests/Feature/Api/StorefrontOrderApiTest.php:110:        ->assertJsonPath('data.order_number', '#1001')
tests/Feature/Api/StorefrontOrderApiTest.php:119:        ->assertJsonPath('data.order_number', '#1001')
tests/Feature/Api/StorefrontOrderApiTest.php:142:    $inventory = InventoryItem::withoutGlobalScopes()->where('variant_id', $variant->getKey())->firstOrFail();
tests/Feature/Api/AdminTaxSettingsApiTest.php:20:    return Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Api/AdminTaxSettingsApiTest.php:25:    return User::query()->where('email', 'admin@acme.test')->firstOrFail();
tests/Feature/Api/AdminTaxSettingsApiTest.php:70:    $settings = TaxSettings::withoutGlobalScopes()->whereKey($store->getKey())->firstOrFail();
tests/Feature/Api/AdminShippingSettingsApiTest.php:21:    return Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Api/AdminShippingSettingsApiTest.php:26:    return User::query()->where('email', 'admin@acme.test')->firstOrFail();
tests/Feature/Api/AdminShippingSettingsApiTest.php:96:    $zone = ShippingZone::withoutGlobalScopes()->where('store_id', $store->getKey())->firstOrFail();
tests/Feature/Api/AdminShippingSettingsApiTest.php:129:    $zone = ShippingZone::withoutGlobalScopes()->where('store_id', $store->getKey())->firstOrFail();
tests/Feature/Admin/SettingsManagementTest.php:31:    $store = Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Admin/SettingsManagementTest.php:39:    return User::query()->where('email', 'admin@acme.test')->firstOrFail();
tests/Feature/Admin/SettingsManagementTest.php:91:    $settings = StoreSettings::query()->whereKey($store->getKey())->firstOrFail();
tests/Feature/Admin/SettingsManagementTest.php:115:        ->firstOrFail();
tests/Feature/Admin/SettingsManagementTest.php:132:        ->firstOrFail();
tests/Feature/Admin/SettingsManagementTest.php:158:    $settings = StoreSettings::query()->whereKey($store->getKey())->firstOrFail()->settings_json;
tests/Feature/Admin/SettingsManagementTest.php:190:    $settings = StoreSettings::query()->whereKey($store->getKey())->firstOrFail()->settings_json;
tests/Feature/Admin/SettingsManagementTest.php:217:    $manual = TaxSettings::withoutGlobalScopes()->whereKey($store->getKey())->firstOrFail();
tests/Feature/Admin/SettingsManagementTest.php:232:    $provider = TaxSettings::withoutGlobalScopes()->whereKey($store->getKey())->firstOrFail();
tests/Feature/Api/AdminStoreSettingsApiTest.php:19:    return Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Api/AdminStoreSettingsApiTest.php:24:    return User::query()->where('email', 'admin@acme.test')->firstOrFail();
tests/Feature/Api/AdminStoreSettingsApiTest.php:75:    $settings = StoreSettings::query()->whereKey($store->getKey())->firstOrFail();
tests/Feature/Api/AdminOrderApiTest.php:28:    return Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Api/AdminOrderApiTest.php:33:    return User::query()->where('email', 'admin@acme.test')->firstOrFail();
tests/Feature/Api/AdminOrderApiTest.php:55:        ->firstOrFail();
tests/Feature/Api/AdminOrderApiTest.php:150:    $fulfillment = Fulfillment::query()->where('order_id', $order->getKey())->firstOrFail();
tests/Feature/Api/AdminCollectionApiTest.php:20:    return Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Api/AdminCollectionApiTest.php:25:    return User::query()->where('email', 'admin@acme.test')->firstOrFail();
tests/Feature/Api/StorefrontCartApiTest.php:20:    return Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Api/StorefrontCartApiTest.php:28:        ->firstOrFail();
tests/Feature/Api/StorefrontCartApiTest.php:33:        ->firstOrFail();
tests/Feature/Api/StorefrontCartApiTest.php:151:    $otherStoreCart = Cart::factory()->create(['store_id' => Store::query()->whereKeyNot($store->getKey())->firstOrFail()->getKey()]);
tests/Feature/Catalog/CatalogUiTest.php:54:    $store = Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Catalog/CatalogUiTest.php:55:    $user = User::query()->where('email', 'admin@acme.test')->firstOrFail();
tests/Feature/Catalog/CatalogUiTest.php:80:    $store = Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Catalog/CatalogUiTest.php:81:    $user = User::query()->where('email', 'admin@acme.test')->firstOrFail();
tests/Feature/Catalog/CatalogUiTest.php:97:    $product = Product::query()->where('handle', 'test-product-created-by-e2e')->firstOrFail();
tests/Feature/Catalog/CatalogUiTest.php:159:    $store = Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Catalog/CatalogUiTest.php:160:    $user = User::query()->where('email', 'admin@acme.test')->firstOrFail();
tests/Feature/Catalog/CatalogUiTest.php:191:    $product = Product::query()->where('handle', 'matrix-product')->firstOrFail();
tests/Feature/Catalog/CatalogUiTest.php:228:    $store = Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Catalog/CatalogUiTest.php:229:    $user = User::query()->where('email', 'admin@acme.test')->firstOrFail();
tests/Feature/Catalog/CatalogUiTest.php:230:    $product = Product::query()->where('handle', 'classic-cotton-t-shirt')->firstOrFail();
tests/Feature/Catalog/CatalogUiTest.php:242:    $collection = Collection::query()->where('handle', 'e2e-test-collection')->firstOrFail();
tests/Browser/SmokeTest.php:19:    return Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Browser/SmokeTest.php:34:        ->firstOrFail();
tests/Browser/SmokeTest.php:44:        ->firstOrFail();
tests/Browser/SmokeTest.php:54:        ->firstOrFail();
tests/Browser/SmokeTest.php:185:    $user = User::query()->where('email', 'admin@acme.test')->firstOrFail();
tests/Browser/Storefront/InventoryTest.php:32:    return Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Browser/Storefront/InventoryTest.php:44:        ->firstOrFail();
tests/Browser/Storefront/InventoryTest.php:99:        ->firstOrFail()
tests/Browser/Storefront/CheckoutTest.php:125:        ->assertSee('#1001')
tests/Browser/Storefront/CheckoutTest.php:238:        ->assertSee('#1001')
tests/Feature/Api/AdminPageApiTest.php:19:    return Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Api/AdminPageApiTest.php:24:    return User::query()->where('email', 'admin@acme.test')->firstOrFail();
tests/Feature/Admin/SearchSettingsTest.php:23:    return Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Admin/SearchSettingsTest.php:28:    return User::query()->where('email', 'admin@acme.test')->firstOrFail();
tests/Feature/Admin/SearchSettingsTest.php:50:    $settings = SearchSettings::withoutGlobalScopes()->where('store_id', $store->getKey())->firstOrFail();
tests/Feature/Storefront/CartCheckoutUiTest.php:32:    $store = Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Storefront/CartCheckoutUiTest.php:43:        ->firstOrFail();
tests/Feature/Storefront/CartCheckoutUiTest.php:48:        ->firstOrFail();
tests/Feature/Storefront/CartCheckoutUiTest.php:90:    $inventory = InventoryItem::withoutGlobalScopes()->where('variant_id', $variant->getKey())->firstOrFail();
tests/Feature/Storefront/CartCheckoutUiTest.php:134:    $checkout = Checkout::withoutGlobalScopes()->where('cart_id', $cart->getKey())->firstOrFail();
tests/Feature/Storefront/CartCheckoutUiTest.php:146:        ->firstOrFail();
tests/Feature/Storefront/CartCheckoutUiTest.php:174:        ->firstOrFail();
tests/Feature/Storefront/CartCheckoutUiTest.php:196:    $checkout = Checkout::withoutGlobalScopes()->where('cart_id', $cart->getKey())->firstOrFail();
tests/Feature/Storefront/CartCheckoutUiTest.php:197:    $inventory = InventoryItem::withoutGlobalScopes()->where('variant_id', $variant->getKey())->firstOrFail();
tests/Feature/Storefront/OrderViewsTest.php:32:    $store = Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Storefront/OrderViewsTest.php:43:        ->firstOrFail();
tests/Feature/Storefront/OrderViewsTest.php:48:        ->firstOrFail();
tests/Feature/Storefront/OrderViewsTest.php:56:        ->firstOrFail();
tests/Feature/Storefront/OrderViewsTest.php:82:    $order = Order::withoutGlobalScopes()->firstOrFail();
tests/Feature/Storefront/OrderViewsTest.php:118:    $checkout = Checkout::withoutGlobalScopes()->where('cart_id', $cart->getKey())->firstOrFail();
tests/Feature/Storefront/OrderViewsTest.php:119:    $inventory = InventoryItem::withoutGlobalScopes()->where('variant_id', $variant->getKey())->firstOrFail();
tests/Feature/Storefront/OrderViewsTest.php:121:    expect(Order::withoutGlobalScopes()->count())->toBe(0)
tests/Feature/Storefront/OrderViewsTest.php:128:    $customer = Customer::withoutGlobalScopes()->where('store_id', $store->getKey())->firstOrFail();
tests/Feature/Storefront/OrderViewsTest.php:159:    $customer = Customer::withoutGlobalScopes()->where('store_id', $store->getKey())->firstOrFail();
tests/Browser/Storefront/CustomerAccountTest.php:44:    return Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Browser/Storefront/CustomerAccountTest.php:54:        ->firstOrFail();
tests/Browser/Storefront/CustomerAccountTest.php:65:    return collect(['#1001', '#1002', '#1004'])
tests/Browser/Storefront/CustomerAccountTest.php:165:        ->assertSee('#1001')
tests/Browser/Storefront/CustomerAccountTest.php:166:        ->assertSee('#1002')
tests/Browser/Storefront/CustomerAccountTest.php:167:        ->assertSee('#1004')
tests/Browser/Storefront/CustomerAccountTest.php:181:        ->assertSee('#1001')
tests/Feature/Storefront/CustomerAccountTest.php:22:    $store = Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Storefront/CustomerAccountTest.php:36:        ->firstOrFail();
tests/Feature/Storefront/CustomerAccountTest.php:58:    $orders = collect(['#1001', '#1002', '#1004'])->map(fn (string $orderNumber): Order => Order::factory()
tests/Feature/Storefront/CustomerAccountTest.php:76:        ->assertSee('#1001')
tests/Feature/Storefront/CustomerAccountTest.php:77:        ->assertSee('#1002')
tests/Feature/Storefront/CustomerAccountTest.php:78:        ->assertSee('#1004');
tests/Feature/Storefront/CustomerAccountTest.php:83:        ->assertSee('#1001')
tests/Feature/Storefront/CustomerAccountTest.php:112:        ->firstOrFail();
tests/Feature/Storefront/CustomerAccountTest.php:131:        ->firstOrFail();
tests/Feature/Storefront/ThemeDataTest.php:84:    $store = Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Storefront/ThemeDataTest.php:95:    $store = Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Storefront/ThemeDataTest.php:99:        ->firstOrFail();
tests/Feature/Storefront/ThemeDataTest.php:116:    $store = Store::query()->where('handle', 'acme-fashion')->firstOrFail();
tests/Feature/Cart/CartServiceTest.php:34:        ->firstOrFail();
tests/Feature/Cart/CartServiceTest.php:98:        ->firstOrFail();


cmd: sed -n '280,420p' app/Livewire/Admin/Dashboard.php


command: sed -n '280,420p' app/Livewire/Admin/Dashboard.php

Dashboard.php

type: read

aggregated_output:
    private function revenueStatuses(): array
    {
        return [
            FinancialStatus::Paid->value,
            FinancialStatus::PartiallyRefunded->value,
        ];
    }

    private function percentChange(int $current, int $previous): float
    {
        if ($previous === 0) {
            return $current > 0 ? 100.0 : 0.0;
        }

        return round((($current - $previous) / $previous) * 100, 1);
    }
}

status: completed


output:
Chunk ID: 2f99ef
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 107
Output:
    private function revenueStatuses(): array
    {
        return [
            FinancialStatus::Paid->value,
            FinancialStatus::PartiallyRefunded->value,
        ];
    }

    private function percentChange(int $current, int $previous): float
    {
        if ($previous === 0) {
            return $current > 0 ? 100.0 : 0.0;
        }

        return round((($current - $previous) / $previous) * 100, 1);
    }
}


cmd: rg -n "current_store_id|current_store|storeUsers|stores\(\)|StoreUser|belongsToMany\(Store" app bootstrap routes database -S


cmd: sed -n '1,220p' database/seeders/StoreUserSeeder.php


cmd: sed -n '1,220p' database/factories/StoreFactory.php


command: sed -n '1,220p' database/seeders/StoreUserSeeder.php

aggregated_output:
<?php

namespace Database\Seeders;

use App\Models\Store;
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class StoreUserSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $user = User::query()->where('email', 'admin@acme.test')->firstOrFail();

        Store::query()->each(function (Store $store) use ($user): void {
            DB::table('store_users')->updateOrInsert(
                [
                    'store_id' => $store->getKey(),
                    'user_id' => $user->getKey(),
                ],
                [
                    'role' => 'owner',
                    'created_at' => now(),
                ],
            );
        });
    }
}


command:
/bin/zsh
-lc
sed -n '1,220p' app/Models/User.php

User.php

cmd: sed -n '1,220p' app/Models/User.php

aggregated_output:
<?php

namespace App\Models;

use App\Enums\StoreUserRole;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
use Laravel\Fortify\TwoFactorAuthenticatable;

class User extends Authenticatable implements MustVerifyEmail
{
    /** @use HasFactory<\Database\Factories\UserFactory> */
    use HasFactory, Notifiable, TwoFactorAuthenticatable;

    /**
     * The attributes that are mass assignable.
     *
     * @var list<string>
     */
    protected $fillable = [
        'name',
        'email',
        'status',
        'password',
        'last_login_at',
    ];

    /**
     * The attributes that should be hidden for serialization.
     *
     * @var list<string>
     */
    protected $hidden = [
        'password_hash',
        'two_factor_secret',
        'two_factor_recovery_codes',
        'remember_token',
    ];

    /**
     * @return BelongsToMany<Store, $this>
     */
    public function stores(): BelongsToMany
    {
        return $this->belongsToMany(Store::class, 'store_users')
            ->using(StoreUser::class)
            ->withPivot('role');
    }

    public function roleForStore(Store $store): ?StoreUserRole
    {
        return $this->roleForStoreId($store->getKey());
    }

    public function roleForStoreId(int $storeId): ?StoreUserRole
    {
        $role = $this->stores()
            ->whereKey($storeId)
            ->first()
            ?->pivot
            ?->role;

        if ($role instanceof StoreUserRole) {
            return $role;
        }

        return is_string($role) ? StoreUserRole::tryFrom($role) : null;
    }

    public function getAuthPassword(): ?string
    {
        return $this->password_hash;
    }

    public function setPasswordAttribute(string $value): void
    {
        $this->attributes['password_hash'] = Hash::needsRehash($value) ? Hash::make($value) : $value;
    }

    public function getPasswordAttribute(): ?string
    {
        return $this->password_hash;
    }

    /**
     * Get the attributes that should be cast.
     *
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'email_verified_at' => 'datetime',
            'last_login_at' => 'datetime',
            'two_factor_confirmed_at' => 'datetime',
        ];
    }

    /**
     * Get the user's initials
     */
    public function initials(): string
    {
        return Str::of($this->name)
            ->explode(' ')
            ->take(2)
            ->map(fn ($word) => Str::substr($word, 0, 1))
            ->implode('');
    }
}


command: sed -n '1,220p' database/factories/StoreFactory.php

aggregated_output:
<?php

namespace Database\Factories;

use App\Enums\StoreStatus;
use App\Models\Organization;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Store>
 */
class StoreFactory extends Factory
{
    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        $name = fake()->company().' Store';

        return [
            'organization_id' => Organization::factory(),
            'name' => $name,
            'handle' => Str::slug(fake()->unique()->words(2, true)),
            'status' => StoreStatus::Active,
            'default_currency' => 'EUR',
            'default_locale' => 'en',
            'timezone' => 'Europe/Berlin',
        ];
    }

    public function suspended(): static
    {
        return $this->state(fn (array $attributes): array => [
            'status' => StoreStatus::Suspended,
        ]);
    }
}


command: rg -n "current_store_id|current_store|storeUsers|stores\(\)|StoreUser|belongsToMany\(Store" app bootstrap routes database -S

type: search

cmd: rg -n "current_store_id|current_store|storeUsers|stores\\(\\)|StoreUser|belongsToMany\\(Store" app bootstrap routes database -S

query: current_store_id|current_store|storeUsers|stores\(\)|StoreUser|belongsToMany\(Store

path: app

aggregated_output:
app/Http/Controllers/Api/Admin/V1/PageController.php:99:            abort_unless($request->user()?->stores()->whereKey($store->getKey())->exists(), 403);
app/Http/Controllers/Api/Admin/V1/PageController.php:102:        app()->instance('current_store', $store);
app/Http/Controllers/Api/Admin/V1/ThemeSettingsController.php:47:            abort_unless($request->user()?->stores()->whereKey($store->getKey())->exists(), 403);
app/Http/Controllers/Api/Admin/V1/ThemeSettingsController.php:50:        app()->instance('current_store', $store);
app/Traits/ChecksStoreRole.php:5:use App\Enums\StoreUserRole;
app/Traits/ChecksStoreRole.php:11:    public function getStoreRole(User $user, ?int $storeId = null): ?StoreUserRole
app/Traits/ChecksStoreRole.php:23:     * @param  array<int, StoreUserRole>  $roles
app/Traits/ChecksStoreRole.php:34:        return $this->hasRole($user, $storeId, [StoreUserRole::Owner]);
app/Traits/ChecksStoreRole.php:39:        return $this->hasRole($user, $storeId, [StoreUserRole::Owner, StoreUserRole::Admin]);
app/Traits/ChecksStoreRole.php:44:        return $this->hasRole($user, $storeId, [StoreUserRole::Owner, StoreUserRole::Admin, StoreUserRole::Staff]);
app/Traits/ChecksStoreRole.php:54:        if (! app()->bound('current_store')) {
app/Traits/ChecksStoreRole.php:58:        $store = app('current_store');
app/Http/Controllers/Api/Admin/V1/ShippingZoneController.php:61:            abort_unless($request->user()?->stores()->whereKey($store->getKey())->exists(), 403);
app/Http/Controllers/Api/Admin/V1/ShippingZoneController.php:64:        app()->instance('current_store', $store);
app/Auth/CustomerUserProvider.php:36:        $store = app()->bound('current_store') ? app('current_store') : null;
app/Models/Concerns/BelongsToStore.php:15:            if ($model->store_id || ! app()->bound('current_store')) {
app/Models/Concerns/BelongsToStore.php:19:            $store = app('current_store');
app/Models/CartLine.php:43:        static::addGlobalScope('current_store', function (Builder $builder): void {
app/Models/CartLine.php:44:            if (! app()->bound('current_store')) {
app/Models/CartLine.php:48:            $store = app('current_store');
app/Models/NavigationItem.php:42:        static::addGlobalScope('current_store', function (Builder $builder): void {
app/Models/NavigationItem.php:43:            if (! app()->bound('current_store')) {
app/Models/NavigationItem.php:47:            $store = app('current_store');
app/Models/ProductOption.php:36:        static::addGlobalScope('current_store', function (Builder $builder): void {
app/Models/ProductOption.php:37:            if (! app()->bound('current_store')) {
app/Models/ProductOption.php:41:            $store = app('current_store');
app/Models/User.php:5:use App\Enums\StoreUserRole;
app/Models/User.php:48:    public function stores(): BelongsToMany
app/Models/User.php:50:        return $this->belongsToMany(Store::class, 'store_users')
app/Models/User.php:51:            ->using(StoreUser::class)
app/Models/User.php:55:    public function roleForStore(Store $store): ?StoreUserRole
app/Models/User.php:60:    public function roleForStoreId(int $storeId): ?StoreUserRole
app/Models/User.php:62:        $role = $this->stores()
app/Models/User.php:68:        if ($role instanceof StoreUserRole) {
app/Models/User.php:72:        return is_string($role) ? StoreUserRole::tryFrom($role) : null;
app/Http/Controllers/Api/Admin/V1/TaxSettingsController.php:60:            abort_unless($request->user()?->stores()->whereKey($store->getKey())->exists(), 403);
app/Http/Controllers/Api/Admin/V1/TaxSettingsController.php:63:        app()->instance('current_store', $store);
app/Models/Organization.php:25:    public function stores(): HasMany
app/Http/Controllers/Api/Admin/V1/CustomerController.php:57:            abort_unless($request->user()?->stores()->whereKey($store->getKey())->exists(), 403);
app/Http/Controllers/Api/Admin/V1/CustomerController.php:60:        app()->instance('current_store', $store);
app/Models/ThemeFile.php:37:        static::addGlobalScope('current_store', function (Builder $builder): void {
app/Models/ThemeFile.php:38:            if (! app()->bound('current_store')) {
app/Models/ThemeFile.php:42:            $store = app('current_store');
app/Models/ProductMedia.php:47:        static::addGlobalScope('current_store', function (Builder $builder): void {
app/Models/ProductMedia.php:48:            if (! app()->bound('current_store')) {
app/Models/ProductMedia.php:52:            $store = app('current_store');
database/seeders/DatabaseSeeder.php:20:            StoreUserSeeder::class,
app/Http/Controllers/Api/Admin/V1/OrderRefundController.php:46:            abort_unless($request->user()?->stores()->whereKey($store->getKey())->exists(), 403);
app/Http/Controllers/Api/Admin/V1/OrderRefundController.php:49:        app()->instance('current_store', $store);
app/Models/Scopes/StoreScope.php:14:        if (! app()->bound('current_store')) {
app/Models/Scopes/StoreSco…5996 chars truncated…eeder extends Seeder
app/Http/Middleware/AuthenticateAdminApi.php:24:        app()->instance('current_store', $store);
app/Http/Middleware/AuthenticateAdminApi.php:27:            if ($request->user()->stores()->whereKey($store->getKey())->exists()) {
app/Enums/StoreUserRole.php:5:enum StoreUserRole: string
app/Providers/AppServiceProvider.php:135:            $store = app()->bound('current_store') ? app('current_store') : null;
app/Livewire/Admin/Settings/Notifications.php:112:        $store = app('current_store');
app/Livewire/Admin/Developers/Index.php:196:        $store = app('current_store');
app/Livewire/Admin/Discounts/Form.php:63:        $store = app('current_store');
app/Livewire/Admin/Discounts/Form.php:87:        $store = app('current_store');
app/Livewire/Admin/Discounts/Form.php:361:        $store = app('current_store');
app/Livewire/Admin/Analytics/Index.php:7:use App\Enums\StoreUserRole;
app/Livewire/Admin/Analytics/Index.php:319:        $store = app('current_store');
app/Livewire/Admin/Analytics/Index.php:335:        return in_array($role, [StoreUserRole::Owner, StoreUserRole::Admin, StoreUserRole::Staff], true);
app/Livewire/Admin/Discounts/Index.php:35:        $store = app('current_store');
app/Livewire/Admin/Settings/Checkout.php:117:        $store = app('current_store');
app/Livewire/Admin/Themes/Editor.php:35:        $store = app('current_store');
app/Livewire/Admin/Settings/Shipping.php:276:        $store = app('current_store');
app/Livewire/Admin/Themes/Index.php:27:        $store = app('current_store');
app/Livewire/Admin/Navigation/Index.php:344:        $store = app('current_store');
app/Livewire/Admin/Settings/Index.php:233:        $store = app('current_store');
app/Livewire/Admin/Apps/Show.php:70:        $store = app('current_store');
app/Livewire/Storefront/Home.php:16:        $store = app('current_store');
app/Livewire/Storefront/CartDrawer.php:76:            app()->instance('current_store', $store);
app/Livewire/Storefront/CartDrawer.php:81:        $store = app('current_store');
app/Livewire/Storefront/Products/Show.php:92:            app()->instance('current_store', $store);
app/Livewire/Storefront/Products/Show.php:97:        $store = app('current_store');
app/Livewire/Admin/Apps/Index.php:65:        $store = app('current_store');
app/Livewire/Admin/Settings/Taxes.php:113:        $store = app('current_store');
app/Livewire/Storefront/Account/Orders/Show.php:22:        $store = app('current_store');
app/Livewire/Admin/Dashboard.php:74:        $store = app('current_store');
app/Livewire/Admin/Customers/Show.php:45:        $store = app('current_store');
app/Livewire/Storefront/Search/Index.php:120:        $store = app('current_store');
app/Livewire/Admin/Pages/Form.php:35:        $store = app('current_store');
app/Livewire/Admin/Pages/Form.php:64:        $store = app('current_store');
app/Livewire/Admin/Pages/Form.php:115:        $store = app('current_store');
app/Livewire/Storefront/Account/Auth/ForgotPassword.php:19:        $store = app('current_store');
app/Livewire/Storefront/Checkout/Confirmation.php:22:        $store = app('current_store');
app/Livewire/Storefront/Account/Orders/Index.php:23:        $store = app('current_store');
app/Livewire/Admin/Customers/Index.php:26:        $store = app('current_store');
app/Livewire/Admin/Pages/Index.php:27:        $store = app('current_store');
app/Livewire/Storefront/Account/Auth/ResetPassword.php:26:        $store = app('current_store');
app/Livewire/Storefront/Checkout/Show.php:266:            app()->instance('current_store', $store);
app/Livewire/Storefront/Checkout/Show.php:271:        $store = app('current_store');
app/Livewire/Admin/Products/Form.php:78:            $store = app('current_store');
app/Livewire/Admin/Products/Form.php:166:        $store = app('current_store');
app/Livewire/Admin/Products/Form.php:773:        $store = app('current_store');
app/Livewire/Admin/Collections/Form.php:38:            $store = app('current_store');
app/Livewire/Admin/Collections/Form.php:73:        $store = app('current_store');
app/Livewire/Storefront/Account/Addresses/Index.php:46:        $store = app('current_store');
app/Livewire/Admin/Orders/Show.php:49:        $store = app('current_store');
app/Livewire/Storefront/Account/Auth/Register.php:27:        $store = app('current_store');
app/Livewire/Storefront/Account/Auth/Register.php:38:        app()->instance('current_store', $store);
app/Livewire/Admin/Search/Settings.php:153:        $store = app('current_store');
app/Livewire/Admin/Orders/Index.php:39:        $store = app('current_store');
app/Livewire/Storefront/Account/Auth/Login.php:25:        $store = app('current_store');
app/Livewire/Storefront/Account/Auth/Login.php:50:        app()->instance('current_store', Store::query()->findOrFail($this->storeId));
app/Livewire/Storefront/Cart/Show.php:155:            app()->instance('current_store', $store);
app/Livewire/Storefront/Cart/Show.php:160:        $store = app('current_store');


output:
Chunk ID: c5b007
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 3999
Output:
app/Http/Controllers/Api/Admin/V1/PageController.php:99:            abort_unless($request->user()?->stores()->whereKey($store->getKey())->exists(), 403);
app/Http/Controllers/Api/Admin/V1/PageController.php:102:        app()->instance('current_store', $store);
app/Http/Controllers/Api/Admin/V1/ThemeSettingsController.php:47:            abort_unless($request->user()?->stores()->whereKey($store->getKey())->exists(), 403);
app/Http/Controllers/Api/Admin/V1/ThemeSettingsController.php:50:        app()->instance('current_store', $store);
app/Traits/ChecksStoreRole.php:5:use App\Enums\StoreUserRole;
app/Traits/ChecksStoreRole.php:11:    public function getStoreRole(User $user, ?int $storeId = null): ?StoreUserRole
app/Traits/ChecksStoreRole.php:23:     * @param  array<int, StoreUserRole>  $roles
app/Traits/ChecksStoreRole.php:34:        return $this->hasRole($user, $storeId, [StoreUserRole::Owner]);
app/Traits/ChecksStoreRole.php:39:        return $this->hasRole($user, $storeId, [StoreUserRole::Owner, StoreUserRole::Admin]);
app/Traits/ChecksStoreRole.php:44:        return $this->hasRole($user, $storeId, [StoreUserRole::Owner, StoreUserRole::Admin, StoreUserRole::Staff]);
app/Traits/ChecksStoreRole.php:54:        if (! app()->bound('current_store')) {
app/Traits/ChecksStoreRole.php:58:        $store = app('current_store');
app/Http/Controllers/Api/Admin/V1/ShippingZoneController.php:61:            abort_unless($request->user()?->stores()->whereKey($store->getKey())->exists(), 403);
app/Http/Controllers/Api/Admin/V1/ShippingZoneController.php:64:        app()->instance('current_store', $store);
app/Auth/CustomerUserProvider.php:36:        $store = app()->bound('current_store') ? app('current_store') : null;
app/Models/Concerns/BelongsToStore.php:15:            if ($model->store_id || ! app()->bound('current_store')) {
app/Models/Concerns/BelongsToStore.php:19:            $store = app('current_store');
app/Models/CartLine.php:43:        static::addGlobalScope('current_store', function (Builder $builder): void {
app/Models/CartLine.php:44:            if (! app()->bound('current_store')) {
app/Models/CartLine.php:48:            $store = app('current_store');
app/Models/NavigationItem.php:42:        static::addGlobalScope('current_store', function (Builder $builder): void {
app/Models/NavigationItem.php:43:            if (! app()->bound('current_store')) {
app/Models/NavigationItem.php:47:            $store = app('current_store');
app/Models/ProductOption.php:36:        static::addGlobalScope('current_store', function (Builder $builder): void {
app/Models/ProductOption.php:37:            if (! app()->bound('current_store')) {
app/Models/ProductOption.php:41:            $store = app('current_store');
app/Models/User.php:5:use App\Enums\StoreUserRole;
app/Models/User.php:48:    public function stores(): BelongsToMany
app/Models/User.php:50:        return $this->belongsToMany(Store::class, 'store_users')
app/Models/User.php:51:            ->using(StoreUser::class)
app/Models/User.php:55:    public function roleForStore(Store $store): ?StoreUserRole
app/Models/User.php:60:    public function roleForStoreId(int $storeId): ?StoreUserRole
app/Models/User.php:62:        $role = $this->stores()
app/Models/User.php:68:        if ($role instanceof StoreUserRole) {
app/Models/User.php:72:        return is_string($role) ? StoreUserRole::tryFrom($role) : null;
app/Http/Controllers/Api/Admin/V1/TaxSettingsController.php:60:            abort_unless($request->user()?->stores()->whereKey($store->getKey())->exists(), 403);
app/Http/Controllers/Api/Admin/V1/TaxSettingsController.php:63:        app()->instance('current_store', $store);
app/Models/Organization.php:25:    public function stores(): HasMany
app/Http/Controllers/Api/Admin/V1/CustomerController.php:57:            abort_unless($request->user()?->stores()->whereKey($store->getKey())->exists(), 403);
app/Http/Controllers/Api/Admin/V1/CustomerController.php:60:        app()->instance('current_store', $store);
app/Models/ThemeFile.php:37:        static::addGlobalScope('current_store', function (Builder $builder): void {
app/Models/ThemeFile.php:38:            if (! app()->bound('current_store')) {
app/Models/ThemeFile.php:42:            $store = app('current_store');
app/Models/ProductMedia.php:47:        static::addGlobalScope('current_store', function (Builder $builder): void {
app/Models/ProductMedia.php:48:            if (! app()->bound('current_store')) {
app/Models/ProductMedia.php:52:            $store = app('current_store');
database/seeders/DatabaseSeeder.php:20:            StoreUserSeeder::class,
app/Http/Controllers/Api/Admin/V1/OrderRefundController.php:46:            abort_unless($request->user()?->stores()->whereKey($store->getKey())->exists(), 403);
app/Http/Controllers/Api/Admin/V1/OrderRefundController.php:49:        app()->instance('current_store', $store);
app/Models/Scopes/StoreScope.php:14:        if (! app()->bound('current_store')) {
app/Models/Scopes/StoreScope.php:18:        $store = app('current_store');
app/Models/ProductOptionValue.php:36:        static::addGlobalScope('current_store', function (Builder $builder): void {
app/Models/ProductOptionValue.php:37:            if (! app()->bound('current_store')) {
app/Models/ProductOptionValue.php:41:            $store = app('current_store');
app/Http/Controllers/Api/Admin/V1/StoreSettingsController.php:91:            abort_unless($request->user()?->stores()->whereKey($store->getKey())->exists(), 403);
app/Http/Controllers/Api/Admin/V1/StoreSettingsController.php:94:        app()->instance('current_store', $store);
app/Models/ShippingRate.php:40:        static::addGlobalScope('current_store', function (Builder $builder): void {
app/Models/ShippingRate.php:41:            if (! app()->bound('current_store')) {
app/Models/ShippingRate.php:45:            $store = app('current_store');
app/Models/Store.php:53:            ->using(StoreUser::class)
app/Models/ThemeSettings.php:31:        static::addGlobalScope('current_store', function (Builder $builder): void {
app/Models/ThemeSettings.php:32:            if (! app()->bound('current_store')) {
app/Models/ThemeSettings.php:36:            $store = app('current_store');
app/Http/Controllers/Api/Admin/V1/ProductController.php:66:            abort_unless($request->user()?->stores()->whereKey($store->getKey())->exists(), 403);
app/Http/Controllers/Api/Admin/V1/ProductController.php:69:        app()->instance('current_store', $store);
app/Models/StoreUser.php:5:use App\Enums\StoreUserRole;
app/Models/StoreUser.php:8:class StoreUser extends Pivot
app/Models/StoreUser.php:33:            'role' => StoreUserRole::class,
app/Models/ProductVariant.php:51:        static::addGlobalScope('current_store', function (Builder $builder): void {
app/Models/ProductVariant.php:52:            if (! app()->bound('current_store')) {
app/Models/ProductVariant.php:56:            $store = app('current_store');
app/Http/Controllers/Api/Admin/V1/ThemeController.php:68:            abort_unless($request->user()?->stores()->whereKey($store->getKey())->exists(), 403);
app/Http/Controllers/Api/Admin/V1/ThemeController.php:71:        app()->instance('current_store', $store);
app/Http/Controllers/Api/Admin/V1/DiscountController.php:78:            abort_unless($request->user()?->stores()->whereKey($store->getKey())->exists(), 403);
app/Http/Controllers/Api/Admin/V1/DiscountController.php:81:        app()->instance('current_store', $store);
app/Http/Controllers/Api/Admin/V1/OrderFulfillmentController.php:40:            abort_unless($request->user()?->stores()->whereKey($store->getKey())->exists(), 403);
app/Http/Controllers/Api/Admin/V1/OrderFulfillmentController.php:43:        app()->instance('current_store', $store);
app/Http/Controllers/Api/Admin/V1/ShippingRateController.php:55:            abort_unless($request->user()?->stores()->whereKey($store->getKey())->exists(), 403);
app/Http/Controllers/Api/Admin/V1/ShippingRateController.php:58:        app()->instance('current_store', $store);
app/Http/Controllers/Api/Admin/V1/OrderController.php:63:            abort_unless($request->user()?->stores()->whereKey($store->getKey())->exists(), 403);
app/Http/Controllers/Api/Admin/V1/OrderController.php:66:        app()->instance('current_store', $store);
app/Http/Requests/Api/Storefront/V1/StoreCartRequest.php:27:        $store = app()->bound('current_store') ? app('current_store') : null;
app/Http/Controllers/Api/Admin/V1/OrderExportController.php:51:            abort_unless($request->user()?->stores()->whereKey($store->getKey())->exists(), 403);
app/Http/Controllers/Api/Admin/V1/OrderExportController.php:54:        app()->instance('current_store', $store);
app/Http/Controllers/Storefront/Account/Auth/CustomerPasswordResetController.php:48:        $store = app('current_store');
app/Http/Controllers/Api/Admin/V1/AnalyticsSummaryController.php:67:            abort_unless($request->user()?->stores()->whereKey($store->getKey())->exists(), 403);
app/Http/Controllers/Api/Admin/V1/AnalyticsSummaryController.php:70:        app()->instance('current_store', $store);
app/Http/Controllers/Api/Admin/V1/CollectionController.php:106:            abort_unless($request->user()?->stores()->whereKey($store->getKey())->exists(), 403);
app/Http/Controllers/Api/Admin/V1/CollectionController.php:109:        app()->instance('current_store', $store);
app/Http/Controllers/Api/Admin/V1/SearchIndexController.php:69:            abort_unless($request->user()?->stores()->whereKey($store->getKey())->exists(), 403);
app/Http/Controllers/Api/Admin/V1/SearchIndexController.php:72:        app()->instance('current_store', $store);
app/Http/Controllers/Api/Storefront/V1/CartController.php:31:        $store = app('current_store');
app/Http/Controllers/Api/Storefront/V1/OrderController.php:16:        $store = app('current_store');
app/Http/Controllers/Api/Storefront/V1/SearchController.php:56:        $store = app('current_store');
app/Http/Controllers/Api/Storefront/V1/AnalyticsEventController.php:22:        $store = app('current_store');
app/Http/Middleware/ResolveStore.php:28:        app()->instance('current_store', $store);
app/Http/Middleware/ResolveStore.php:63:        $storeId = $request->session()->get('current_store_id');
app/Http/Middleware/ResolveStore.php:66:            $storeId = $user->stores()->oldest('stores.id')->value('stores.id');
app/Http/Middleware/ResolveStore.php:69:                $request->session()->put('current_store_id', $storeId);
app/Http/Middleware/ResolveStore.php:73:        if (! $storeId || ! $user->stores()->whereKey($storeId)->exists()) {
app/Http/Middleware/CheckStoreRole.php:5:use App\Enums\StoreUserRole;
app/Http/Middleware/CheckStoreRole.php:20:        $store = app()->bound('current_store') ? app('current_store') : null;
app/Http/Middleware/CheckStoreRole.php:34:            fn (string $role): ?StoreUserRole => StoreUserRole::tryFrom($role),
database/seeders/StoreUserSeeder.php:10:class StoreUserSeeder extends Seeder
app/Http/Middleware/AuthenticateAdminApi.php:24:        app()->instance('current_store', $store);
app/Http/Middleware/AuthenticateAdminApi.php:27:            if ($request->user()->stores()->whereKey($store->getKey())->exists()) {
app/Enums/StoreUserRole.php:5:enum StoreUserRole: string
app/Providers/AppServiceProvider.php:135:            $store = app()->bound('current_store') ? app('current_store') : null;
app/Livewire/Admin/Settings/Notifications.php:112:        $store = app('current_store');
app/Livewire/Admin/Developers/Index.php:196:        $store = app('current_store');
app/Livewire/Admin/Discounts/Form.php:63:        $store = app('current_store');
app/Livewire/Admin/Discounts/Form.php:87:        $store = app('current_store');
app/Livewire/Admin/Discounts/Form.php:361:        $store = app('current_store');
app/Livewire/Admin/Analytics/Index.php:7:use App\Enums\StoreUserRole;
app/Livewire/Admin/Analytics/Index.php:319:        $store = app('current_store');
app/Livewire/Admin/Analytics/Index.php:335:        return in_array($role, [StoreUserRole::Owner, StoreUserRole::Admin, StoreUserRole::Staff], true);
app/Livewire/Admin/Discounts/Index.php:35:        $store = app('current_store');
app/Livewire/Admin/Settings/Checkout.php:117:        $store = app('current_store');
app/Livewire/Admin/Themes/Editor.php:35:        $store = app('current_store');
app/Livewire/Admin/Settings/Shipping.php:276:        $store = app('current_store');
app/Livewire/Admin/Themes/Index.php:27:        $store = app('current_store');
app/Livewire/Admin/Navigation/Index.php:344:        $store = app('current_store');
app/Livewire/Admin/Settings/Index.php:233:        $store = app('current_store');
app/Livewire/Admin/Apps/Show.php:70:        $store = app('current_store');
app/Livewire/Storefront/Home.php:16:        $store = app('current_store');
app/Livewire/Storefront/CartDrawer.php:76:            app()->instance('current_store', $store);
app/Livewire/Storefront/CartDrawer.php:81:        $store = app('current_store');
app/Livewire/Storefront/Products/Show.php:92:            app()->instance('current_store', $store);
app/Livewire/Storefront/Products/Show.php:97:        $store = app('current_store');
app/Livewire/Admin/Apps/Index.php:65:        $store = app('current_store');
app/Livewire/Admin/Settings/Taxes.php:113:        $store = app('current_store');
app/Livewire/Storefront/Account/Orders/Show.php:22:        $store = app('current_store');
app/Livewire/Admin/Dashboard.php:74:        $store = app('current_store');
app/Livewire/Admin/Customers/Show.php:45:        $store = app('current_store');
app/Livewire/Storefront/Search/Index.php:120:        $store = app('current_store');
app/Livewire/Admin/Pages/Form.php:35:        $store = app('current_store');
app/Livewire/Admin/Pages/Form.php:64:        $store = app('current_store');
app/Livewire/Admin/Pages/Form.php:115:        $store = app('current_store');
app/Livewire/Storefront/Account/Auth/ForgotPassword.php:19:        $store = app('current_store');
app/Livewire/Storefront/Checkout/Confirmation.php:22:        $store = app('current_store');
app/Livewire/Storefront/Account/Orders/Index.php:23:        $store = app('current_store');
app/Livewire/Admin/Customers/Index.php:26:        $store = app('current_store');
app/Livewire/Admin/Pages/Index.php:27:        $store = app('current_store');
app/Livewire/Storefront/Account/Auth/ResetPassword.php:26:        $store = app('current_store');
app/Livewire/Storefront/Checkout/Show.php:266:            app()->instance('current_store', $store);
app/Livewire/Storefront/Checkout/Show.php:271:        $store = app('current_store');
app/Livewire/Admin/Products/Form.php:78:            $store = app('current_store');
app/Livewire/Admin/Products/Form.php:166:        $store = app('current_store');
app/Livewire/Admin/Products/Form.php:773:        $store = app('current_store');
app/Livewire/Admin/Collections/Form.php:38:            $store = app('current_store');
app/Livewire/Admin/Collections/Form.php:73:        $store = app('current_store');
app/Livewire/Storefront/Account/Addresses/Index.php:46:        $store = app('current_store');
app/Livewire/Admin/Orders/Show.php:49:        $store = app('current_store');
app/Livewire/Storefront/Account/Auth/Register.php:27:        $store = app('current_store');
app/Livewire/Storefront/Account/Auth/Register.php:38:        app()->instance('current_store', $store);
app/Livewire/Admin/Search/Settings.php:153:        $store = app('current_store');
app/Livewire/Admin/Orders/Index.php:39:        $store = app('current_store');
app/Livewire/Storefront/Account/Auth/Login.php:25:        $store = app('current_store');
app/Livewire/Storefront/Account/Auth/Login.php:50:        app()->instance('current_store', Store::query()->findOrFail($this->storeId));
app/Livewire/Storefront/Cart/Show.php:155:            app()->instance('current_store', $store);
app/Livewire/Storefront/Cart/Show.php:160:        $store = app('current_store');


output:
Chunk ID: 6e9e2a
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 194
Output:
<?php

namespace Database\Seeders;

use App\Models\Store;
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class StoreUserSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $user = User::query()->where('email', 'admin@acme.test')->firstOrFail();

        Store::query()->each(function (Store $store) use ($user): void {
            DB::table('store_users')->updateOrInsert(
                [
                    'store_id' => $store->getKey(),
                    'user_id' => $user->getKey(),
                ],
                [
                    'role' => 'owner',
                    'created_at' => now(),
                ],
            );
        });
    }
}


output:
Chunk ID: eb2fe0
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 706
Output:
<?php

namespace App\Models;

use App\Enums\StoreUserRole;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
use Laravel\Fortify\TwoFactorAuthenticatable;

class User extends Authenticatable implements MustVerifyEmail
{
    /** @use HasFactory<\Database\Factories\UserFactory> */
    use HasFactory, Notifiable, TwoFactorAuthenticatable;

    /**
     * The attributes that are mass assignable.
     *
     * @var list<string>
     */
    protected $fillable = [
        'name',
        'email',
        'status',
        'password',
        'last_login_at',
    ];

    /**
     * The attributes that should be hidden for serialization.
     *
     * @var list<string>
     */
    protected $hidden = [
        'password_hash',
        'two_factor_secret',
        'two_factor_recovery_codes',
        'remember_token',
    ];

    /**
     * @return BelongsToMany<Store, $this>
     */
    public function stores(): BelongsToMany
    {
        return $this->belongsToMany(Store::class, 'store_users')
            ->using(StoreUser::class)
            ->withPivot('role');
    }

    public function roleForStore(Store $store): ?StoreUserRole
    {
        return $this->roleForStoreId($store->getKey());
    }

    public function roleForStoreId(int $storeId): ?StoreUserRole
    {
        $role = $this->stores()
            ->whereKey($storeId)
            ->first()
            ?->pivot
            ?->role;

        if ($role instanceof StoreUserRole) {
            return $role;
        }

        return is_string($role) ? StoreUserRole::tryFrom($role) : null;
    }

    public function getAuthPassword(): ?string
    {
        return $this->password_hash;
    }

    public function setPasswordAttribute(string $value): void
    {
        $this->attributes['password_hash'] = Hash::needsRehash($value) ? Hash::make($value) : $value;
    }

    public function getPasswordAttribute(): ?string
    {
        return $this->password_hash;
    }

    /**
     * Get the attributes that should be cast.
     *
     * @return array<string, string>
     */
    protected function casts(): array
    {
        return [
            'email_verified_at' => 'datetime',
            'last_login_at' => 'datetime',
            'two_factor_confirmed_at' => 'datetime',
        ];
    }

    /**
     * Get the user's initials
     */
    public function initials(): string
    {
        return Str::of($this->name)
            ->explode(' ')
            ->take(2)
            ->map(fn ($word) => Str::substr($word, 0, 1))
            ->implode('');
    }
}


output:
Chunk ID: 9eb2e6
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 257
Output:
<?php

namespace Database\Factories;

use App\Enums\StoreStatus;
use App\Models\Organization;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

/**
 * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Store>
 */
class StoreFactory extends Factory
{
    /**
     * Define the model's default state.
     *
     * @return array<string, mixed>
     */
    public function definition(): array
    {
        $name = fake()->company().' Store';

        return [
            'organization_id' => Organization::factory(),
            'name' => $name,
            'handle' => Str::slug(fake()->unique()->words(2, true)),
            'status' => StoreStatus::Active,
            'default_currency' => 'EUR',
            'default_locale' => 'en',
            'timezone' => 'Europe/Berlin',
        ];
    }

    public function suspended(): static
    {
        return $this->state(fn (array $attributes): array => [
            'status' => StoreStatus::Suspended,
        ]);
    }
}


cmd: sed -n '1,340p' tests/Feature/Orders/OrderServiceTest.php


cmd: sed -n '1,220p' tests/Feature/Api/StorefrontOrderApiTest.php


cmd: sed -n '1,240p' tests/Browser/Storefront/CheckoutTest.php


command: sed -n '1,220p' tests/Feature/Api/StorefrontOrderApiTest.php

aggregated_output:
<?php

use App\Enums\CheckoutStatus;
use App\Models\Checkout;
use App\Models\InventoryItem;
use App\Models\Product;
use App\Models\ProductVariant;
use App\Models\Store;
use Database\Seeders\DatabaseSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;

uses(RefreshDatabase::class);

beforeEach(function (): void {
    $this->withoutVite();
    $this->seed(DatabaseSeeder::class);
});

function storefrontOrderApiStore(): Store
{
    return Store::query()->where('handle', 'acme-fashion')->firstOrFail();
}

function storefrontOrderApiVariant(Store $store): ProductVariant
{
    $product = Product::withoutGlobalScopes()
        ->where('store_id', $store->getKey())
        ->where('handle', 'classic-cotton-t-shirt')
        ->firstOrFail();

    $variant = ProductVariant::withoutGlobalScopes()
        ->where('product_id', $product->getKey())
        ->oldest('position')
        ->firstOrFail();

    InventoryItem::withoutGlobalScopes()
        ->where('variant_id', $variant->getKey())
        ->update([
            'quantity_on_hand' => 20,
            'quantity_reserved' => 0,
        ]);

    return $variant->refresh();
}

/**
 * @return array{0: int, 1: ProductVariant}
 */
function storefrontOrderApiCheckout(object $testCase, string $remoteAddress = '10.0.0.41'): array
{
    $store = storefrontOrderApiStore();
    $variant = storefrontOrderApiVariant($store);
    $api = fn () => $testCase->withServerVariables(['REMOTE_ADDR' => $remoteAddress])->withHeader('Host', 'shop.test');

    $cartId = $api()
        ->postJson('/api/storefront/v1/carts')
        ->assertCreated()['data']['id'];

    $api()
        ->postJson("/api/storefront/v1/carts/{$cartId}/lines", [
            'variant_id' => $variant->getKey(),
            'quantity' => 1,
        ])
        ->assertCreated();

    $checkoutId = $api()
        ->postJson('/api/storefront/v1/checkouts', [
            'cart_id' => $cartId,
            'email' => 'buyer@example.test',
        ])
        ->assertCreated()['data']['id'];

    $addressResponse = $api()
        ->putJson("/api/storefront/v1/checkouts/{$checkoutId}/address", [
            'shipping_address' => [
                'first_name' => 'Test',
                'last_name' => 'Buyer',
                'address1' => 'Main Street 1',
                'city' => 'Berlin',
                'country' => 'DE',
                'postal_code' => '10115',
            ],
        ])
        ->assertOk();

    $api()
        ->putJson("/api/storefront/v1/checkouts/{$checkoutId}/shipping-method", [
            'shipping_rate_id' => $addressResponse['data']['available_shipping_rates'][0]['id'],
        ])
        ->assertOk();

    return [$checkoutId, $variant];
}

test('storefront order api pays a checkout and exposes token-gated order lookup', function (): void {
    [$checkoutId] = storefrontOrderApiCheckout($this);
    $api = fn () => $this->withServerVariables(['REMOTE_ADDR' => '10.0.0.41'])->withHeader('Host', 'shop.test');

    $payResponse = $api()
        ->postJson("/api/storefront/v1/checkouts/{$checkoutId}/pay", [
            'payment_method' => 'credit_card',
            'card_number' => '4242 4242 4242 4242',
            'card_holder' => 'Test Buyer',
            'card_expiry' => '12/30',
            'card_cvc' => '123',
        ]);

    $payResponse
        ->assertOk()
        ->assertJsonPath('data.order_number', '#1001')
        ->assertJsonPath('data.financial_status', 'paid')
        ->assertJsonCount(1, 'data.lines');

    $token = $payResponse['data']['access_token'];

    $api()
        ->getJson('/api/storefront/v1/orders/%231001?token='.$token)
        ->assertOk()
        ->assertJsonPath('data.order_number', '#1001')
        ->assertJsonPath('data.total_amount', $payResponse['data']['total_amount']);

    $api()
        ->getJson('/api/storefront/v1/orders/%231001?token=bad-token')
        ->assertNotFound();
});

test('storefront order api returns payment failures and releases reservations', function (): void {
    [$checkoutId, $variant] = storefrontOrderApiCheckout($this, '10.0.0.42');
    $api = fn () => $this->withServerVariables(['REMOTE_ADDR' => '10.0.0.42'])->withHeader('Host', 'shop.test');

    $api()
        ->postJson("/api/storefront/v1/checkouts/{$checkoutId}/pay", [
            'payment_method' => 'credit_card',
            'card_number' => '4000 0000 0000 0002',
            'card_holder' => 'Test Buyer',
            'card_expiry' => '12/30',
            'card_cvc' => '123',
        ])
        ->assertStatus(402);

    $checkout = Checkout::withoutGlobalScopes()->findOrFail($checkoutId);
    $inventory = InventoryItem::withoutGlobalScopes()->where('variant_id', $variant->getKey())->firstOrFail();

    expect($checkout->status)->toBe(CheckoutStatus::ShippingSelected)
        ->and($inventory->quantity_reserved)->toBe(0);
});


command: sed -n '1,340p' tests/Feature/Orders/OrderServiceTest.php

aggregated_output:
<?php

use App\Enums\CartStatus;
use App\Enums\CheckoutStatus;
use App\Enums\DiscountType;
use App\Enums\DiscountValueType;
use App\Enums\FinancialStatus;
use App\Enums\OrderStatus;
use App\Enums\PaymentStatus;
use App\Events\OrderCreated;
use App\Events\OrderPaid;
use App\Exceptions\PaymentFailedException;
use App\Models\Checkout;
use App\Models\Discount;
use App\Models\InventoryItem;
use App\Models\Order;
use App\Models\Payment;
use App\Models\Product;
use App\Models\ProductVariant;
use App\Models\ShippingRate;
use App\Models\ShippingZone;
use App\Models\Store;
use App\Models\StoreSettings;
use App\Models\TaxSettings;
use App\Services\CartService;
use App\Services\CheckoutService;
use App\Services\PricingEngine;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Event;

uses(RefreshDatabase::class);

function orderCompletionStore(int $start = 1001): Store
{
    $store = Store::factory()->create();
    app()->instance('current_store', $store);

    StoreSettings::query()->create([
        'store_id' => $store->getKey(),
        'settings_json' => [
            'order_number_prefix' => '#',
            'order_number_start' => $start,
        ],
    ]);

    TaxSettings::withoutGlobalScopes()->create([
        'store_id' => $store->getKey(),
        'mode' => 'manual',
        'provider' => 'none',
        'prices_include_tax' => false,
        'config_json' => ['default_rate_bps' => 0, 'shipping_taxable' => false],
    ]);

    return $store;
}

function orderCompletionVariant(Store $store, int $price = 2500, int $stock = 10): ProductVariant
{
    $product = Product::factory()
        ->withDefaultVariant($price)
        ->create(['store_id' => $store->getKey()]);
    $variant = ProductVariant::withoutGlobalScopes()
        ->where('product_id', $product->getKey())
        ->firstOrFail();

    InventoryItem::withoutGlobalScopes()
        ->where('variant_id', $variant->getKey())
        ->update([
            'quantity_on_hand' => $stock,
            'quantity_reserved' => 0,
        ]);

    return $variant->refresh();
}

function orderCompletionShippingRate(Store $store): ShippingRate
{
    $zone = ShippingZone::withoutGlobalScopes()
        ->where('store_id', $store->getKey())
        ->where('name', 'Germany')
        ->first();

    if (! $zone instanceof ShippingZone) {
        $zone = ShippingZone::withoutGlobalScopes()->create([
            'store_id' => $store->getKey(),
            'name' => 'Germany',
            'countries_json' => ['DE'],
            'regions_json' => [],
        ]);
    }

    $rate = ShippingRate::withoutGlobalScopes()
        ->where('zone_id', $zone->getKey())
        ->where('name', 'Standard')
        ->first();

    if ($rate instanceof ShippingRate) {
        return $rate;
    }

    return ShippingRate::withoutGlobalScopes()->create([
        'zone_id' => $zone->getKey(),
        'name' => 'Standard',
        'type' => 'flat',
        'config_json' => ['amount' => 499],
        'is_active' => true,
    ]);
}

/**
 * @return array{0: Checkout, 1: ProductVariant, 2: \App\Models\Cart}
 */
function orderCompletionCheckout(Store $store, string $paymentMethod = 'credit_card', ?string $discountCode = null): array
{
    $variant = orderCompletionVariant($store);
    $rate = orderCompletionShippingRate($store);
    $cart = app(CartService::class)->create($store);

    app(CartService::class)->addLine($cart, $variant->getKey(), 2);

    $checkout = app(CheckoutService::class)->createFromCart($cart);
    $checkout = app(CheckoutService::class)->setAddress($checkout, [
        'email' => 'buyer@example.test',
        'shipping_address' => [
            'first_name' => 'Test',
            'last_name' => 'Buyer',
            'address1' => 'Main Street 1',
            'city' => 'Berlin',
            'country' => 'DE',
            'postal_code' => '10115',
        ],
    ]);
    $checkout = app(CheckoutService::class)->setShippingMethod($checkout, $rate->getKey());

    if ($discountCode !== null) {
        $checkout->forceFill(['discount_code' => $discountCode])->save();
        app(PricingEngine::class)->calculate($checkout);
    }

    $checkout = app(CheckoutService::class)->selectPaymentMethod($checkout, $paymentMethod);

    return [$checkout, $variant, $cart];
}

test('checkout completion creates a paid order and commits inventory', function () {
    $store = orderCompletionStore();
    $discount = Discount::factory()
        ->fixed(500)
        ->create([
            'store_id' => $store->getKey(),
            'code' => 'SAVE500',
        ]);
    [$checkout, $variant, $cart] = orderCompletionCheckout($store, discountCode: 'SAVE500');

    Event::fake();

    $order = app(CheckoutService::class)->completeCheckout($checkout, [
        'card_number' => '4242 4242 4242 4242',
    ]);

    expect($order->order_number)->toBe('#1001')
        ->and($order->status)->toBe(OrderStatus::Paid)
        ->and($order->financial_status)->toBe(FinancialStatus:…1596 chars truncated…cent,
            'value_amount' => 10,
        ]);
    [$checkout] = orderCompletionCheckout($store);

    $order = app(CheckoutService::class)->completeCheckout($checkout, [
        'card_number' => '4242 4242 4242 4242',
    ]);

    expect($order->discount_amount)->toBe(500)
        ->and($order->lines->first()->discount_allocations_json)->toBe([[
            'discount_id' => $automatic->getKey(),
            'code' => null,
            'amount' => 500,
        ]]);
});

test('checkout completion keeps explicit and automatic discount allocations separate', function () {
    $store = orderCompletionStore();
    $codeDiscount = Discount::factory()
        ->create([
            'store_id' => $store->getKey(),
            'code' => 'SAVE10',
            'value_type' => DiscountValueType::Percent,
            'value_amount' => 10,
        ]);
    $automatic = Discount::factory()
        ->create([
            'store_id' => $store->getKey(),
            'type' => DiscountType::Automatic,
            'code' => null,
            'value_type' => DiscountValueType::Percent,
            'value_amount' => 10,
        ]);
    [$checkout] = orderCompletionCheckout($store, discountCode: 'SAVE10');

    $order = app(CheckoutService::class)->completeCheckout($checkout, [
        'card_number' => '4242 4242 4242 4242',
    ]);

    expect($order->discount_amount)->toBe(950)
        ->and($order->lines->first()->discount_allocations_json)->toBe([
            [
                'discount_id' => $codeDiscount->getKey(),
                'code' => 'SAVE10',
                'amount' => 500,
            ],
            [
                'discount_id' => $automatic->getKey(),
                'code' => null,
                'amount' => 450,
            ],
        ]);
});

test('checkout completion is idempotent for the same checkout', function () {
    $store = orderCompletionStore();
    [$checkout, $variant] = orderCompletionCheckout($store);

    $order = app(CheckoutService::class)->completeCheckout($checkout, [
        'card_number' => '4242 4242 4242 4242',
    ]);
    $sameOrder = app(CheckoutService::class)->completeCheckout($checkout->refresh(), [
        'card_number' => '4000 0000 0000 0002',
    ]);

    expect($sameOrder->is($order))->toBeTrue()
        ->and(Order::withoutGlobalScopes()->count())->toBe(1)
        ->and(Payment::query()->count())->toBe(1)
        ->and(InventoryItem::withoutGlobalScopes()->where('variant_id', $variant->getKey())->first()?->quantity_on_hand)->toBe(8)
        ->and(InventoryItem::withoutGlobalScopes()->where('variant_id', $variant->getKey())->first()?->quantity_reserved)->toBe(0);
});

test('bank transfer completion creates a pending order and keeps inventory reserved', function () {
    $store = orderCompletionStore();
    [$checkout, $variant] = orderCompletionCheckout($store, paymentMethod: 'bank_transfer');

    Event::fake();

    $order = app(CheckoutService::class)->completeCheckout($checkout);

    expect($order->status)->toBe(OrderStatus::Pending)
        ->and($order->financial_status)->toBe(FinancialStatus::Pending)
        ->and($order->payments->first()->status)->toBe(PaymentStatus::Pending)
        ->and($checkout->refresh()->status)->toBe(CheckoutStatus::Completed);

    $inventory = InventoryItem::withoutGlobalScopes()->where('variant_id', $variant->getKey())->firstOrFail();

    expect($inventory->quantity_on_hand)->toBe(10)
        ->and($inventory->quantity_reserved)->toBe(2);

    Event::assertDispatched(OrderCreated::class);
    Event::assertNotDispatched(OrderPaid::class);
});

test('payment failures release reserved inventory and allow checkout retry', function () {
    $store = orderCompletionStore();
    [$checkout, $variant] = orderCompletionCheckout($store);

    expect(fn () => app(CheckoutService::class)->completeCheckout($checkout, [
        'card_number' => '4000 0000 0000 0002',
    ]))->toThrow(PaymentFailedException::class);

    $inventory = InventoryItem::withoutGlobalScopes()->where('variant_id', $variant->getKey())->firstOrFail();

    expect(Order::withoutGlobalScopes()->count())->toBe(0)
        ->and($inventory->quantity_on_hand)->toBe(10)
        ->and($inventory->quantity_reserved)->toBe(0)
        ->and($checkout->refresh()->status)->toBe(CheckoutStatus::ShippingSelected)
        ->and($checkout->payment_method)->toBeNull();
});

test('order numbers increment sequentially per store', function () {
    $store = orderCompletionStore(start: 5001);
    [$firstCheckout] = orderCompletionCheckout($store);
    [$secondCheckout] = orderCompletionCheckout($store);

    $firstOrder = app(CheckoutService::class)->completeCheckout($firstCheckout, [
        'card_number' => '4242 4242 4242 4242',
    ]);
    $secondOrder = app(CheckoutService::class)->completeCheckout($secondCheckout, [
        'card_number' => '4242 4242 4242 4242',
    ]);

    expect($firstOrder->order_number)->toBe('#5001')
        ->and($secondOrder->order_number)->toBe('#5002');
});


output:
Chunk ID: e91e20
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 2899
Output:
<?php

use App\Enums\CartStatus;
use App\Enums\CheckoutStatus;
use App\Enums\DiscountType;
use App\Enums\DiscountValueType;
use App\Enums\FinancialStatus;
use App\Enums\OrderStatus;
use App\Enums\PaymentStatus;
use App\Events\OrderCreated;
use App\Events\OrderPaid;
use App\Exceptions\PaymentFailedException;
use App\Models\Checkout;
use App\Models\Discount;
use App\Models\InventoryItem;
use App\Models\Order;
use App\Models\Payment;
use App\Models\Product;
use App\Models\ProductVariant;
use App\Models\ShippingRate;
use App\Models\ShippingZone;
use App\Models\Store;
use App\Models\StoreSettings;
use App\Models\TaxSettings;
use App\Services\CartService;
use App\Services\CheckoutService;
use App\Services\PricingEngine;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Event;

uses(RefreshDatabase::class);

function orderCompletionStore(int $start = 1001): Store
{
    $store = Store::factory()->create();
    app()->instance('current_store', $store);

    StoreSettings::query()->create([
        'store_id' => $store->getKey(),
        'settings_json' => [
            'order_number_prefix' => '#',
            'order_number_start' => $start,
        ],
    ]);

    TaxSettings::withoutGlobalScopes()->create([
        'store_id' => $store->getKey(),
        'mode' => 'manual',
        'provider' => 'none',
        'prices_include_tax' => false,
        'config_json' => ['default_rate_bps' => 0, 'shipping_taxable' => false],
    ]);

    return $store;
}

function orderCompletionVariant(Store $store, int $price = 2500, int $stock = 10): ProductVariant
{
    $product = Product::factory()
        ->withDefaultVariant($price)
        ->create(['store_id' => $store->getKey()]);
    $variant = ProductVariant::withoutGlobalScopes()
        ->where('product_id', $product->getKey())
        ->firstOrFail();

    InventoryItem::withoutGlobalScopes()
        ->where('variant_id', $variant->getKey())
        ->update([
            'quantity_on_hand' => $stock,
            'quantity_reserved' => 0,
        ]);

    return $variant->refresh();
}

function orderCompletionShippingRate(Store $store): ShippingRate
{
    $zone = ShippingZone::withoutGlobalScopes()
        ->where('store_id', $store->getKey())
        ->where('name', 'Germany')
        ->first();

    if (! $zone instanceof ShippingZone) {
        $zone = ShippingZone::withoutGlobalScopes()->create([
            'store_id' => $store->getKey(),
            'name' => 'Germany',
            'countries_json' => ['DE'],
            'regions_json' => [],
        ]);
    }

    $rate = ShippingRate::withoutGlobalScopes()
        ->where('zone_id', $zone->getKey())
        ->where('name', 'Standard')
        ->first();

    if ($rate instanceof ShippingRate) {
        return $rate;
    }

    return ShippingRate::withoutGlobalScopes()->create([
        'zone_id' => $zone->getKey(),
        'name' => 'Standard',
        'type' => 'flat',
        'config_json' => ['amount' => 499],
        'is_active' => true,
    ]);
}

/**
 * @return array{0: Checkout, 1: ProductVariant, 2: \App\Models\Cart}
 */
function orderCompletionCheckout(Store $store, string $paymentMethod = 'credit_card', ?string $discountCode = null): array
{
    $variant = orderCompletionVariant($store);
    $rate = orderCompletionShippingRate($store);
    $cart = app(CartService::class)->create($store);

    app(CartService::class)->addLine($cart, $variant->getKey(), 2);

    $checkout = app(CheckoutService::class)->createFromCart($cart);
    $checkout = app(CheckoutService::class)->setAddress($checkout, [
        'email' => 'buyer@example.test',
        'shipping_address' => [
            'first_name' => 'Test',
            'last_name' => 'Buyer',
            'address1' => 'Main Street 1',
            'city' => 'Berlin',
            'country' => 'DE',
            'postal_code' => '10115',
        ],
    ]);
    $checkout = app(CheckoutService::class)->setShippingMethod($checkout, $rate->getKey());

    if ($discountCode !== null) {
        $checkout->forceFill(['discount_code' => $discountCode])->save();
        app(PricingEngine::class)->calculate($checkout);
    }

    $checkout = app(CheckoutService::class)->selectPaymentMethod($checkout, $paymentMethod);

    return [$checkout, $variant, $cart];
}

test('checkout completion creates a paid order and commits inventory', function () {
    $store = orderCompletionStore();
    $discount = Discount::factory()
        ->fixed(500)
        ->create([
            'store_id' => $store->getKey(),
            'code' => 'SAVE500',
        ]);
    [$checkout, $variant, $cart] = orderCompletionCheckout($store, discountCode: 'SAVE500');

    Event::fake();

    $order = app(CheckoutService::class)->completeCheckout($checkout, [
        'card_number' => '4242 4242 4242 4242',
    ]);

    expect($order->order_number)->toBe('#1001')
        ->and($order->status)->toBe(OrderStatus::Paid)
        ->and($order->financial_status)->toBe(FinancialStatus::Paid)
        ->and($order->total_amount)->toBe(4999)
        ->and($order->lines)->toHaveCount(1)
        ->and($order->lines->first()->title_snapshot)->toContain($variant->product->title)
        ->and($order->lines->first()->discount_allocations_json)->toBe([[
            'discount_id' => $discount->getKey(),
            'code' => 'SAVE500',
            'amount' => 500,
        ]])
        ->and($order->payments)->toHaveCount(1)
        ->and($order->payments->first()->status)->toBe(PaymentStatus::Captured)
        ->and($order->payments->first()->raw_json_encrypted['success'])->toBeTrue()
        ->and($cart->refresh()->status)->toBe(CartStatus::Converted)
        ->and($checkout->refresh()->status)->toBe(CheckoutStatus::Completed)
        ->and($discount->refresh()->usage_count)->toBe(1);

    $inventory = InventoryItem::withoutGlobalScopes()->where('variant_id', $variant->getKey())->firstOrFail();

    expect($inventory->quantity_on_hand)->toBe(8)
        ->and($inventory->quantity_reserved)->toBe(0);

    Event::assertDispatched(OrderCreated::class, fn (OrderCreated $event): bool => $event->order->is($order));
    Event::assertDispatched(OrderPaid::class, fn (OrderPaid $event): bool => $event->order->is($order));
});

test('checkout completion attributes automatic discounts on order lines', function () {
    $store = orderCompletionStore();
    $automatic = Discount::factory()
        ->create([
            'store_id' => $store->getKey(),
            'type' => DiscountType::Automatic,
            'code' => null,
            'value_type' => DiscountValueType::Percent,
            'value_amount' => 10,
        ]);
    [$checkout] = orderCompletionCheckout($store);

    $order = app(CheckoutService::class)->completeCheckout($checkout, [
        'card_number' => '4242 4242 4242 4242',
    ]);

    expect($order->discount_amount)->toBe(500)
        ->and($order->lines->first()->discount_allocations_json)->toBe([[
            'discount_id' => $automatic->getKey(),
            'code' => null,
            'amount' => 500,
        ]]);
});

test('checkout completion keeps explicit and automatic discount allocations separate', function () {
    $store = orderCompletionStore();
    $codeDiscount = Discount::factory()
        ->create([
            'store_id' => $store->getKey(),
            'code' => 'SAVE10',
            'value_type' => DiscountValueType::Percent,
            'value_amount' => 10,
        ]);
    $automatic = Discount::factory()
        ->create([
            'store_id' => $store->getKey(),
            'type' => DiscountType::Automatic,
            'code' => null,
            'value_type' => DiscountValueType::Percent,
            'value_amount' => 10,
        ]);
    [$checkout] = orderCompletionCheckout($store, discountCode: 'SAVE10');

    $order = app(CheckoutService::class)->completeCheckout($checkout, [
        'card_number' => '4242 4242 4242 4242',
    ]);

    expect($order->discount_amount)->toBe(950)
        ->and($order->lines->first()->discount_allocations_json)->toBe([
            [
                'discount_id' => $codeDiscount->getKey(),
                'code' => 'SAVE10',
                'amount' => 500,
            ],
            [
                'discount_id' => $automatic->getKey(),
                'code' => null,
                'amount' => 450,
            ],
        ]);
});

test('checkout completion is idempotent for the same checkout', function () {
    $store = orderCompletionStore();
    [$checkout, $variant] = orderCompletionCheckout($store);

    $order = app(CheckoutService::class)->completeCheckout($checkout, [
        'card_number' => '4242 4242 4242 4242',
    ]);
    $sameOrder = app(CheckoutService::class)->completeCheckout($checkout->refresh(), [
        'card_number' => '4000 0000 0000 0002',
    ]);

    expect($sameOrder->is($order))->toBeTrue()
        ->and(Order::withoutGlobalScopes()->count())->toBe(1)
        ->and(Payment::query()->count())->toBe(1)
        ->and(InventoryItem::withoutGlobalScopes()->where('variant_id', $variant->getKey())->first()?->quantity_on_hand)->toBe(8)
        ->and(InventoryItem::withoutGlobalScopes()->where('variant_id', $variant->getKey())->first()?->quantity_reserved)->toBe(0);
});

test('bank transfer completion creates a pending order and keeps inventory reserved', function () {
    $store = orderCompletionStore();
    [$checkout, $variant] = orderCompletionCheckout($store, paymentMethod: 'bank_transfer');

    Event::fake();

    $order = app(CheckoutService::class)->completeCheckout($checkout);

    expect($order->status)->toBe(OrderStatus::Pending)
        ->and($order->financial_status)->toBe(FinancialStatus::Pending)
        ->and($order->payments->first()->status)->toBe(PaymentStatus::Pending)
        ->and($checkout->refresh()->status)->toBe(CheckoutStatus::Completed);

    $inventory = InventoryItem::withoutGlobalScopes()->where('variant_id', $variant->getKey())->firstOrFail();

    expect($inventory->quantity_on_hand)->toBe(10)
        ->and($inventory->quantity_reserved)->toBe(2);

    Event::assertDispatched(OrderCreated::class);
    Event::assertNotDispatched(OrderPaid::class);
});

test('payment failures release reserved inventory and allow checkout retry', function () {
    $store = orderCompletionStore();
    [$checkout, $variant] = orderCompletionCheckout($store);

    expect(fn () => app(CheckoutService::class)->completeCheckout($checkout, [
        'card_number' => '4000 0000 0000 0002',
    ]))->toThrow(PaymentFailedException::class);

    $inventory = InventoryItem::withoutGlobalScopes()->where('variant_id', $variant->getKey())->firstOrFail();

    expect(Order::withoutGlobalScopes()->count())->toBe(0)
        ->and($inventory->quantity_on_hand)->toBe(10)
        ->and($inventory->quantity_reserved)->toBe(0)
        ->and($checkout->refresh()->status)->toBe(CheckoutStatus::ShippingSelected)
        ->and($checkout->payment_method)->toBeNull();
});

test('order numbers increment sequentially per store', function () {
    $store = orderCompletionStore(start: 5001);
    [$firstCheckout] = orderCompletionCheckout($store);
    [$secondCheckout] = orderCompletionCheckout($store);

    $firstOrder = app(CheckoutService::class)->completeCheckout($firstCheckout, [
        'card_number' => '4242 4242 4242 4242',
    ]);
    $secondOrder = app(CheckoutService::class)->completeCheckout($secondCheckout, [
        'card_number' => '4242 4242 4242 4242',
    ]);

    expect($firstOrder->order_number)->toBe('#5001')
        ->and($secondOrder->order_number)->toBe('#5002');
});


output:
Chunk ID: 9423d4
Wall time: 0.0000 seconds
Process exited with code 0
Original token count: 1213
Output:
<?php

use App\Enums\CheckoutStatus;
use App\Models\Checkout;
use App\Models\InventoryItem;
use App\Models\Product;
use App\Models\ProductVariant;
use App\Models\Store;
use Database\Seeders\DatabaseSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;

uses(RefreshDatabase::class);

beforeEach(function (): void {
    $this->withoutVite();
    $this->seed(DatabaseSeeder::class);
});

function storefrontOrderApiStore(): Store
{
    return Store::query()->where('handle', 'acme-fashion')->firstOrFail();
}

function storefrontOrderApiVariant(Store $store): ProductVariant
{
    $product = Product::withoutGlobalScopes()
        ->where('store_id', $store->getKey())
        ->where('handle', 'classic-cotton-t-shirt')
        ->firstOrFail();

    $variant = ProductVariant::withoutGlobalScopes()
        ->where('product_id', $product->getKey())
        ->oldest('position')
        ->firstOrFail();

    InventoryItem::withoutGlobalScopes()
        ->where('variant_id', $variant->getKey())
        ->update([
            'quantity_on_hand' => 20,
            'quantity_reserved' => 0,
        ]);

    return $variant->refresh();
}

/**
 * @return array{0: int, 1: ProductVariant}
 */
function storefrontOrderApiCheckout(object $testCase, string $remoteAddress = '10.0.0.41'): array
{
    $store = storefrontOrderApiStore();
    $variant = storefrontOrderApiVariant($store);
    $api = fn () => $testCase->withServerVariables(['REMOTE_ADDR' => $remoteAddress])->withHeader('Host', 'shop.test');

    $cartId = $api()
        ->postJson('/api/storefront/v1/carts')
        ->assertCreated()['data']['id'];

    $api()
        ->postJson("/api/storefront/v1/carts/{$cartId}/lines", [
            'variant_id' => $variant->getKey(),
            'quantity' => 1,
        ])
        ->assertCreated();

    $checkoutId = $api()
        ->postJson('/api/storefront/v1/checkouts', [
            'cart_id' => $cartId,
            'email' => 'buyer@example.test',
        ])
        ->assertCreated()['data']['id'];

    $addressResponse = $api()
        ->putJson("/api/storefront/v1/checkouts/{$checkoutId}/address", [
            'shipping_address' => [
                'first_name' => 'Test',
                'last_name' => 'Buyer',
                'address1' => 'Main Street 1',
                'city' => 'Berlin',
                'country' => 'DE',
                'postal_code' => '10115',
            ],
        ])
        ->assertOk();

    $api()
        ->putJson("/api/storefront/v1/checkouts/{$checkoutId}/shipping-method", [
            'shipping_rate_id' => $addressResponse['data']['available_shipping_rates'][0]['id'],
        ])
        ->assertOk();

    return [$checkoutId, $variant];
}

test('storefront order api pays a checkout and exposes token-gated order lookup', function (): void {
    [$checkoutId] = storefrontOrderApiCheckout($this);
    $api = fn () => $this->withServerVariables(['REMOTE_ADDR' => '10.0.0.41'])->withHeader('Host', 'shop.test');

    $payResponse = $api()
        ->postJson("/api/storefront/v1/checkouts/{$checkoutId}/pay", [
            'payment_method' => 'credit_card',
            'card_number' => '4242 4242 4242 4242',
            'card_holder' => 'Test Buyer',
            'card_expiry' => '12/30',
            'card_cvc' => '123',
        ]);

    $payResponse
        ->assertOk()
        ->assertJsonPath('data.order_number', '#1001')
        ->assertJsonPath('data.financial_status', 'paid')
        ->assertJsonCount(1, 'data.lines');

    $token = $payResponse['data']['access_token'];

    $api()
        ->getJson('/api/storefront/v1/orders/%231001?token='.$token)
        ->assertOk()
        ->assertJsonPath('data.order_number', '#1001')
        ->assertJsonPath('data.total_amount', $payResponse['data']['total_amount']);

    $api()
        ->getJson('/api/storefront/v1/orders/%231001?token=bad-token')
        ->assertNotFound();
});

test('storefront order api returns payment failures and releases reservations', function (): void {
    [$checkoutId, $variant] = storefrontOrderApiCheckout($this, '10.0.0.42');
    $api = fn () => $this->withServerVariables(['REMOTE_ADDR' => '10.0.0.42'])->withHeader('Host', 'shop.test');

    $api()
        ->postJson("/api/storefront/v1/checkouts/{$checkoutId}/pay", [
            'payment_method' => 'credit_card',
            'card_number' => '4000 0000 0000 0002',
            'card_holder' => 'Test Buyer',
            'card_expiry' => '12/30',
            'card_cvc' => '123',
        ])
        ->assertStatus(402);

    $checkout = Checkout::withoutGlobalScopes()->findOrFail($checkoutId);
    $inventory = InventoryItem::withoutGlobalScopes()->where('variant_id', $variant->getKey())->firstOrFail();

    expect($checkout->status)->toBe(CheckoutStatus::ShippingSelected)
        ->and($inventory->quantity_reserved)->toBe(0);
});