the browser-facing portion of osu!
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add class based factory for Store models

nanaya d9324fa2 92675840

+275 -255
+52 -41
database/factories/Store/OrderFactory.php
··· 3 3 // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0. 4 4 // See the LICENCE file in the repository root for full licence text. 5 5 6 - $factory->define(App\Models\Store\Order::class, function (Faker\Generator $faker) { 7 - return [ 8 - 'user_id' => function () { 9 - return App\Models\User::factory()->create(['user_sig' => ''])->user_id; 10 - }, 11 - ]; 12 - }); 6 + declare(strict_types=1); 7 + 8 + namespace Database\Factories\Store; 9 + 10 + use App\Models\Store\Order; 11 + use App\Models\User; 12 + use Carbon\Carbon; 13 + use Database\Factories\Factory; 14 + 15 + class OrderFactory extends Factory 16 + { 17 + protected $model = Order::class; 18 + 19 + public function checkout(): static 20 + { 21 + return $this->state(['status' => 'checkout']); 22 + } 13 23 14 - $factory->state(App\Models\Store\Order::class, 'paid', function (Faker\Generator $faker) use ($factory) { 15 - $date = Carbon\Carbon::now(); 24 + public function definition(): array 25 + { 26 + return [ 27 + 'user_id' => User::factory(), 28 + ]; 29 + } 16 30 17 - return [ 18 - 'paid_at' => $date, 19 - 'status' => 'paid', 20 - 'transaction_id' => "test-{$date->timestamp}", 21 - ]; 22 - }); 31 + public function paid(): static 32 + { 33 + $date = Carbon::now(); 23 34 24 - $factory->state(App\Models\Store\Order::class, 'incart', function (Faker\Generator $faker) { 25 - return [ 26 - 'status' => 'incart', 27 - ]; 28 - }); 35 + return $this->state([ 36 + 'paid_at' => $date, 37 + 'status' => 'paid', 38 + 'transaction_id' => "test-{$date->timestamp}", 39 + ]); 40 + } 29 41 30 - $factory->state(App\Models\Store\Order::class, 'processing', function (Faker\Generator $faker) { 31 - return [ 32 - 'status' => 'processing', 33 - ]; 34 - }); 42 + public function incart(): static 43 + { 44 + return $this->state(['status' => 'incart']); 45 + } 35 46 36 - $factory->state(App\Models\Store\Order::class, 'checkout', function (Faker\Generator $faker) { 37 - return [ 38 - 'status' => 'checkout', 39 - ]; 40 - }); 47 + public function processing(): static 48 + { 49 + return $this->state(['status' => 'processing']); 50 + } 41 51 42 - $factory->state(App\Models\Store\Order::class, 'shipped', function (Faker\Generator $faker) { 43 - return [ 44 - 'status' => 'shipped', 45 - ]; 46 - }); 52 + public function shipped(): static 53 + { 54 + return $this->state(['status' => 'shipped']); 55 + } 47 56 48 - $factory->state(App\Models\Store\Order::class, 'shopify', function (Faker\Generator $faker) { 49 - return [ 50 - // Doesn't need to be a gid for tests. 51 - 'transaction_id' => App\Models\Store\Order::PROVIDER_SHOPIFY.'-'.now()->timestamp, 52 - ]; 53 - }); 57 + public function shopify(): static 58 + { 59 + return $this->state([ 60 + // Doesn't need to be a gid for tests. 61 + 'transaction_id' => Order::PROVIDER_SHOPIFY.'-'.time(), 62 + ]); 63 + } 64 + }
+42 -35
database/factories/Store/OrderItemFactory.php
··· 3 3 // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0. 4 4 // See the LICENCE file in the repository root for full licence text. 5 5 6 + declare(strict_types=1); 7 + 8 + namespace Database\Factories\Store; 9 + 6 10 use App\Models\Store\Order; 7 11 use App\Models\Store\OrderItem; 8 12 use App\Models\Store\Product; 13 + use Database\Factories\Factory; 9 14 10 - $factory->define(App\Models\Store\OrderItem::class, function (Faker\Generator $faker) { 11 - return [ 12 - 'order_id' => function () { 13 - return factory(Order::class)->create()->order_id; 14 - }, 15 - 'product_id' => function () { 16 - return factory(Product::class)->create()->product_id; 17 - }, 18 - 'quantity' => 1, 19 - 'cost' => 12.0, 20 - ]; 21 - }); 15 + class OrderItemFactory extends Factory 16 + { 17 + protected $model = OrderItem::class; 18 + 19 + public function definition(): array 20 + { 21 + return [ 22 + 'cost' => 12.0, 23 + 'order_id' => Order::factory(), 24 + 'product_id' => Product::factory(), 25 + 'quantity' => 1, 26 + ]; 27 + } 22 28 23 - $factory->state(OrderItem::class, 'supporter_tag', function (Faker\Generator $faker) use ($factory) { 24 - return [ 25 - 'product_id' => Product::customClass(Product::SUPPORTER_TAG_NAME)->first(), 26 - 'cost' => 4, 27 - 'extra_data' => function (array $self) { 28 - // find the user for the generated item's order 29 - $order = Order::find($self['order_id']); 30 - $user = $order->user; 29 + public function supporterTag(): static 30 + { 31 + return $this->state([ 32 + 'cost' => 4, 33 + 'extra_data' => function (array $attributes) { 34 + $user = Order::find($attributes['order_id'])->user; 31 35 32 - return [ 33 - 'target_id' => $user->getKey(), 34 - 'username' => $user->username, 35 - 'duration' => 1, 36 - ]; 37 - }, 38 - ]; 39 - }); 36 + return [ 37 + 'duration' => 1, 38 + 'target_id' => (string) $user->getKey(), 39 + 'username' => $user->username, 40 + ]; 41 + }, 42 + 'product_id' => Product::customClass('supporter-tag')->first(), 43 + ]); 44 + } 40 45 41 - $factory->state(OrderItem::class, 'username_change', function (Faker\Generator $faker) use ($factory) { 42 - return [ 43 - 'product_id' => Product::customClass('username-change')->first(), 44 - 'cost' => 0, 45 - 'extra_info' => 'new_username', 46 - ]; 47 - }); 46 + public function usernameChange(): static 47 + { 48 + return $this->state([ 49 + 'cost' => 0, 50 + 'extra_info' => 'new_username', 51 + 'product_id' => Product::customClass('username-change')->first(), 52 + ]); 53 + } 54 + }
+78 -76
database/factories/Store/ProductFactory.php
··· 3 3 // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0. 4 4 // See the LICENCE file in the repository root for full licence text. 5 5 6 - /* 7 - |-------------------------------------------------------------------------- 8 - | Model Factories 9 - |-------------------------------------------------------------------------- 10 - | 11 - | Here you may define all of your model factories. Model factories give 12 - | you a convenient way to create models for testing and seeding your 13 - | database. Just tell the factory how a default model should look. 14 - | 15 - */ 6 + declare(strict_types=1); 7 + 8 + namespace Database\Factories\Store; 9 + 10 + use App\Models\Store\Product; 11 + use Database\Factories\Factory; 12 + 13 + class ProductFactory extends Factory 14 + { 15 + protected $model = Product::class; 16 16 17 - $factory->define(App\Models\Store\Product::class, function (Faker\Generator $faker) { 18 - return [ 19 - 'name' => 'Imagination / '.$faker->colorName, 20 - 'cost' => 16.00, 21 - 'weight' => 100, 22 - 'base_shipping' => 5.00, 23 - 'next_shipping' => 4.00, 24 - 'stock' => rand(1, 100), 25 - 'max_quantity' => 1, 26 - ]; 27 - }); 17 + public function childBanners(): static 18 + { 19 + return $this->state([ 20 + 'base_shipping' => 0.00, 21 + 'cost' => 5.00, 22 + 'custom_class' => 'mwc7-supporter', 23 + 'display_order' => -10, 24 + 'max_quantity' => 1, 25 + 'next_shipping' => 0.00, 26 + 'stock' => null, 27 + 'weight' => null, 28 + ]); 29 + } 28 30 29 - $factory->state(App\Models\Store\Product::class, 'master_tshirt', function (Faker\Generator $faker) { 30 - return [ 31 - 'name' => 'osu! t-shirt (triangles) / '.$faker->colorName, 32 - 'cost' => 16.00, 33 - 'weight' => 100, 34 - 'base_shipping' => 5.00, 35 - 'next_shipping' => 4.00, 36 - 'stock' => rand(1, 100), 37 - 'max_quantity' => 5, 38 - 'header_description' => '# osu! t-shirt swag', 39 - 'promoted' => 1, 40 - 'description' => "Brand new osu! t-shirts have arrived! Featuring a tasty triangle design by osu! designer flyte, it's a welcome addition to any avid osu! player’s wardrobe. 31 + public function childTshirt(): static 32 + { 33 + return $this->state([ 34 + 'base_shipping' => 5.00, 35 + 'cost' => 16.00, 36 + 'max_quantity' => 5, 37 + 'name' => fn() => "osu! t-shirt (triangles) / {$this->faker->colorName}", 38 + 'next_shipping' => 4.00, 39 + 'stock' => rand(1, 100), 40 + 'weight' => 100, 41 + ]); 42 + } 43 + 44 + public function definition(): array 45 + { 46 + return [ 47 + 'base_shipping' => 5.00, 48 + 'cost' => 16.00, 49 + 'max_quantity' => 1, 50 + 'name' => fn() => "Imagination / {$this->faker->colorName}", 51 + 'next_shipping' => 4.00, 52 + 'stock' => rand(1, 100), 53 + 'weight' => 100, 54 + ]; 55 + } 56 + 57 + public function disabled(): static 58 + { 59 + return $this->state(['enabled' => false]); 60 + } 61 + 62 + public function masterTshirt(): static 63 + { 64 + return $this->state([ 65 + 'base_shipping' => 5.00, 66 + 'cost' => 16.00, 67 + 'description' => <<<EOF 68 + Brand new osu! t-shirts have arrived! Featuring a tasty triangle design by osu! designer flyte, it's a welcome addition to any avid osu! player’s wardrobe. 41 69 42 70 * 100% cotton 43 71 * Medium weight, pre-shrunk ··· 52 80 ``` 53 81 54 82 NOTE: These are Japanese sizes. Overseas customers are advised to check the size chart above! 55 - ", 56 - 'header_image' => 'https://puu.sh/hzgoB/1142f14e8b.jpg', 57 - 'images_json' => json_encode([ 58 - ['https://puu.sh/hxpsp/d0b8704769.jpg', 'https://puu.sh/hxpsp/d0b8704769.jpg'], 59 - ['https://puu.sh/hxptO/71121e05e7.jpg', 'https://puu.sh/hxptO/71121e05e7.jpg'], 60 - ['https://puu.sh/hzfUF/1b9af4dbd1.jpg', 'https://puu.sh/hzfUF/1b9af4dbd1.jpg'], 61 - ]), 62 - ]; 63 - }); 64 - 65 - $factory->state(App\Models\Store\Product::class, 'child_tshirt', function (Faker\Generator $faker) { 66 - return [ 67 - 'name' => 'osu! t-shirt (triangles) / '.$faker->colorName, 68 - 'cost' => 16.00, 69 - 'weight' => 100, 70 - 'base_shipping' => 5.00, 71 - 'next_shipping' => 4.00, 72 - 'stock' => rand(1, 100), 73 - 'max_quantity' => 5, 74 - ]; 75 - }); 76 - 77 - $factory->state(App\Models\Store\Product::class, 'child_banners', function (Faker\Generator $faker) { 78 - $params = [ 79 - // 'name' => 'supply your own name', 80 - 'cost' => 5.00, 81 - 'weight' => null, 82 - 'stock' => null, 83 - 'base_shipping' => 0.00, 84 - 'next_shipping' => 0.00, 85 - 'max_quantity' => 1, 86 - 'display_order' => -10, 87 - 'custom_class' => 'mwc7-supporter', 88 - ]; 89 - 90 - return $params; 91 - }); 92 - 93 - $factory->state(App\Models\Store\Product::class, 'disabled', function (Faker\Generator $faker) { 94 - return [ 95 - 'enabled' => false, 96 - ]; 97 - }); 83 + EOF, 84 + 'header_description' => '# osu! t-shirt swag', 85 + 'header_image' => 'https://puu.sh/hzgoB/1142f14e8b.jpg', 86 + 'images_json' => json_encode([ 87 + ['https://puu.sh/hxpsp/d0b8704769.jpg', 'https://puu.sh/hxpsp/d0b8704769.jpg'], 88 + ['https://puu.sh/hxptO/71121e05e7.jpg', 'https://puu.sh/hxptO/71121e05e7.jpg'], 89 + ['https://puu.sh/hzfUF/1b9af4dbd1.jpg', 'https://puu.sh/hzfUF/1b9af4dbd1.jpg'], 90 + ]), 91 + 'max_quantity' => 5, 92 + 'name' => fn() => "osu! t-shirt (triangles) / {$this->faker->colorName}", 93 + 'next_shipping' => 4.00, 94 + 'promoted' => 1, 95 + 'stock' => rand(1, 100), 96 + 'weight' => 100, 97 + ]); 98 + } 99 + }
+8 -8
database/seeders/ModelSeeders/ProductSeeder.php
··· 28 28 $this->product_ids = []; 29 29 $this->count = 0; 30 30 31 - $master_tshirt = factory(Product::class)->states('master_tshirt')->create(); 32 - $child_shirts = factory(Product::class, 7)->states('child_tshirt')->create([ 33 - 'master_product_id' => $master_tshirt->product_id, 31 + $master_tshirt = Product::factory()->masterTshirt()->create(); 32 + $child_shirts = Product::factory()->count(7)->childTshirt()->create([ 33 + 'master_product_id' => $master_tshirt, 34 34 ])->each(function ($s) { 35 35 $this->product_ids[] = $s->product_id; 36 36 $this->count++; ··· 69 69 $countries = Country::limit(6)->get()->toArray(); 70 70 $master_country = array_shift($countries); 71 71 72 - $master = factory(Product::class)->states('child_banners')->create([ 73 - 'name' => "{$tournament->name} Support Banner ({$master_country['name']})", 72 + $master = Product::factory()->childBanners()->create([ 74 73 'description' => ':)', 74 + 'display_order' => 0, 75 75 'header_description' => "# {$tournament->name} Support Banners\nYayifications", 76 + 'name' => "{$tournament->name} Support Banner ({$master_country['name']})", 76 77 'promoted' => true, 77 - 'display_order' => 0, 78 78 ]); 79 79 80 80 $type_mappings_json = [ ··· 85 85 ]; 86 86 87 87 foreach ($countries as $country) { 88 - $product = factory(Product::class)->states('child_banners')->create([ 88 + $product = Product::factory()->childBanners()->create([ 89 + 'master_product_id' => $master, 89 90 'name' => "{$tournament->name} Support Banner ({$country['name']})", 90 - 'master_product_id' => $master->product_id, 91 91 ]); 92 92 93 93 $type_mappings_json[$product->product_id] = [
+5 -5
tests/Browser/SanityTest.php
··· 168 168 ]); 169 169 170 170 // factories for /store/* 171 - self::$scaffolding['product'] = factory(Store\Product::class)->states('master_tshirt')->create(); 172 - self::$scaffolding['order'] = factory(Store\Order::class)->states('checkout')->create([ 173 - 'user_id' => self::$scaffolding['user']->getKey(), 171 + self::$scaffolding['product'] = Store\Product::factory()->masterTshirt()->create(); 172 + self::$scaffolding['order'] = Store\Order::factory()->checkout()->create([ 173 + 'user_id' => self::$scaffolding['user'], 174 174 ]); 175 175 self::$scaffolding['checkout'] = new ScaffoldDummy(self::$scaffolding['order']->getKey()); 176 - self::$scaffolding['invoice'] = factory(Store\Order::class)->states('paid')->create([ 177 - 'user_id' => self::$scaffolding['user']->getKey(), 176 + self::$scaffolding['invoice'] = Store\Order::factory()->paid()->create([ 177 + 'user_id' => self::$scaffolding['user'], 178 178 ]); 179 179 180 180 // factories for /community/forums/*
+2 -2
tests/Controllers/Payments/CentiliControllerTest.php
··· 28 28 29 29 public function testWhenPaymentIsInsufficient() 30 30 { 31 - $orderItem = factory(OrderItem::class)->states('supporter_tag')->create(['order_id' => $this->order->order_id]); 31 + $orderItem = OrderItem::factory()->supporterTag()->create(['order_id' => $this->order]); 32 32 33 33 $data = $this->getPostData(['enduserprice' => '479.000']); 34 34 ··· 47 47 Config::set('payments.centili.secret_key', 'secret_key'); 48 48 Config::set('payments.centili.api_key', 'api_key'); 49 49 Config::set('payments.centili.conversion_rate', 120.00); 50 - $this->order = factory(Order::class)->states('checkout')->create(); 50 + $this->order = Order::factory()->checkout()->create(); 51 51 } 52 52 53 53 private function getPostData(array $overrides = [])
+5 -5
tests/Controllers/Payments/ShopifyControllerTest.php
··· 15 15 { 16 16 public function testWebhookOrdersCancelled() 17 17 { 18 - $order = factory(Order::class)->states('paid')->states('shopify')->create(); 18 + $order = Order::factory()->paid()->shopify()->create(); 19 19 $payment = new Payment([ 20 20 'provider' => Order::PROVIDER_SHOPIFY, 21 21 'transaction_id' => $order->getProviderReference(), ··· 40 40 41 41 public function testWebhookOrdersCreate() 42 42 { 43 - $order = factory(Order::class)->states('shopify', 'processing')->create(); 43 + $order = Order::factory()->shopify()->processing()->create(); 44 44 $this->setShopifyPayload([ 45 45 'note_attributes' => [['name' => 'orderId', 'value' => $order->getKey()]], 46 46 ]); ··· 54 54 55 55 public function testWebhookOrdersFulfilled() 56 56 { 57 - $order = factory(Order::class)->states('shopify', 'checkout')->create(); 57 + $order = Order::factory()->shopify()->checkout()->create(); 58 58 $this->setShopifyPayload([ 59 59 'note_attributes' => [['name' => 'orderId', 'value' => $order->getKey()]], 60 60 ]); ··· 69 69 70 70 public function testWebhookOrdersPaid() 71 71 { 72 - $order = factory(Order::class)->states('shopify', 'processing')->create(); 72 + $order = Order::factory()->shopify()->processing()->create(); 73 73 $this->setShopifyPayload([ 74 74 'note_attributes' => [['name' => 'orderId', 'value' => $order->getKey()]], 75 75 ]); ··· 100 100 public function testReplacementOrdersCreatedByDuplicatingShopifyOrderShouldBeIgnored() 101 101 { 102 102 // Orders are already shipped when the replacement gets created. 103 - $order = factory(Order::class)->states('shopify', 'shipped')->create(); 103 + $order = Order::factory()->shopify()->shipped()->create(); 104 104 $oldUpdatedAt = $order->updated_at->copy(); 105 105 106 106 $this->setShopifyPayload([
+1 -1
tests/Controllers/Payments/XsollaControllerTest.php
··· 66 66 { 67 67 parent::setUp(); 68 68 Config::set('payments.xsolla.secret_key', 'magic'); 69 - $this->order = factory(Order::class)->states('checkout')->create(); 69 + $this->order = Order::factory()->checkout()->create(); 70 70 } 71 71 72 72 private function getPostData(array $overrides = [])
+14 -14
tests/Libraries/Fulfillments/BannerFulfillmentTest.php
··· 65 65 static $customClasses = BannerFulfillment::ALLOWED_TAGGED_NAMES; 66 66 foreach ($customClasses as $customClass) { 67 67 // only need the custom_class 68 - $product = factory(Product::class)->create(['custom_class' => $customClass]); 69 - $orderItem = factory(OrderItem::class)->create([ 70 - 'product_id' => $product->product_id, 71 - 'order_id' => $this->order->order_id, 72 - 'cost' => $product->cost, 68 + $product = Product::factory()->create(['custom_class' => $customClass]); 69 + $orderItem = OrderItem::factory()->create([ 70 + 'product_id' => $product, 71 + 'order_id' => $this->order, 72 + 'cost' => $product, 73 73 ]); 74 74 } 75 75 ··· 80 80 81 81 public function testInvalidBannerCustomClasss() 82 82 { 83 - $product = factory(Product::class)->create(['custom_class' => 'invalid-supporter']); 84 - $orderItem = factory(OrderItem::class)->create([ 85 - 'product_id' => $product->product_id, 86 - 'order_id' => $this->order->order_id, 83 + $product = Product::factory()->create(['custom_class' => 'invalid-supporter']); 84 + $orderItem = OrderItem::factory()->create([ 85 + 'product_id' => $product, 86 + 'order_id' => $this->order, 87 87 'cost' => $product->cost, 88 88 ]); 89 89 ··· 100 100 'osu_subscriptionexpiry' => Carbon::now(), 101 101 ]); 102 102 103 - $this->order = factory(Order::class)->states('paid')->create([ 104 - 'user_id' => $this->user->user_id, 103 + $this->order = Order::factory()->paid()->create([ 104 + 'user_id' => $this->user, 105 105 ]); 106 106 107 107 // crap test ··· 112 112 113 113 private function createOrderItem($product) 114 114 { 115 - return factory(OrderItem::class)->create([ 116 - 'product_id' => $product->product_id, 117 - 'order_id' => $this->order->order_id, 115 + return OrderItem::factory()->create([ 116 + 'product_id' => $product, 117 + 'order_id' => $this->order, 118 118 'cost' => $product->cost, 119 119 'extra_data' => [ 120 120 'tournament_id' => $this->tournament->tournament_id,
+6 -6
tests/Libraries/Fulfillments/FulfillmentFactoryTest.php
··· 18 18 { 19 19 public function testCustomClassSupporterTag() 20 20 { 21 - $orderItem = factory(OrderItem::class)->states('supporter_tag')->create(); 21 + $orderItem = OrderItem::factory()->supporterTag()->create(); 22 22 $order = $orderItem->order; 23 23 24 24 $fulfillers = FulfillmentFactory::createFulfillersFor($order); ··· 28 28 29 29 public function testCustomClassUsernameChange() 30 30 { 31 - $orderItem = factory(OrderItem::class)->states('username_change')->create(); 31 + $orderItem = OrderItem::factory()->usernameChange()->create(); 32 32 $order = $orderItem->order; 33 33 34 34 $fulfillers = FulfillmentFactory::createFulfillersFor($order); ··· 38 38 39 39 public function testCustomClassBanner() 40 40 { 41 - $orderItem = factory(OrderItem::class)->create([ 42 - 'product_id' => factory(Product::class)->create(['custom_class' => 'mwc7-supporter'])->product_id, 41 + $orderItem = OrderItem::factory()->create([ 42 + 'product_id' => Product::factory()->create(['custom_class' => 'mwc7-supporter']), 43 43 ]); 44 44 $order = $orderItem->order; 45 45 ··· 50 50 51 51 public function testCustomClassDoesNotExist() 52 52 { 53 - $orderItem = factory(OrderItem::class)->create([ 54 - 'product_id' => factory(Product::class)->create(['custom_class' => 'derp-derp'])->product_id, 53 + $orderItem = OrderItem::factory()->create([ 54 + 'product_id' => Product::factory()->create(['custom_class' => 'derp-derp']), 55 55 ]); 56 56 $order = $orderItem->order; 57 57
+4 -4
tests/Libraries/Fulfillments/SupporterTagFulfillmentTest.php
··· 308 308 'osu_subscriptionexpiry' => Carbon::now(), 309 309 ]); 310 310 311 - $this->order = factory(Order::class)->states('paid')->create([ 312 - 'user_id' => $this->user->user_id, 311 + $this->order = Order::factory()->paid()->create([ 312 + 'user_id' => $this->user, 313 313 ]); 314 314 } 315 315 ··· 342 342 343 343 private function createOrderItem(User $user, int $duration, int $amount, bool $hidden = false) 344 344 { 345 - return factory(OrderItem::class)->states('supporter_tag')->create([ 346 - 'order_id' => $this->order->order_id, 345 + return OrderItem::factory()->supporterTag()->create([ 346 + 'order_id' => $this->order, 347 347 'cost' => $amount, 348 348 'extra_data' => [ 349 349 'duration' => $duration,
+13 -13
tests/Libraries/Fulfillments/UsernameChangeFulfillmentTest.php
··· 20 20 { 21 21 $oldUsername = $this->user->username; 22 22 $newUsername = 'new_username'; 23 - $orderItem = factory(OrderItem::class)->states('username_change')->create([ 24 - 'order_id' => $this->order->order_id, 23 + $orderItem = OrderItem::factory()->usernameChange()->create([ 24 + 'order_id' => $this->order, 25 25 'extra_info' => $newUsername, 26 26 ]); 27 27 ··· 40 40 41 41 $oldUsername = $this->user->username_previous; 42 42 $newUsername = $this->user->username; 43 - $orderItem = factory(OrderItem::class)->states('username_change')->create([ 44 - 'order_id' => $this->order->order_id, 43 + $orderItem = OrderItem::factory()->usernameChange()->create([ 44 + 'order_id' => $this->order, 45 45 'extra_info' => $newUsername, 46 46 ]); 47 47 ··· 55 55 56 56 public function testRevokeWhenNameDoesNotMatch() 57 57 { 58 - $orderItem = factory(OrderItem::class)->states('username_change')->create([ 59 - 'order_id' => $this->order->order_id, 58 + $orderItem = OrderItem::factory()->usernameChange()->create([ 59 + 'order_id' => $this->order, 60 60 'extra_info' => 'herpderp', 61 61 ]); 62 62 ··· 68 68 69 69 public function testRevokeWhenPreviousUsernameIsNull() 70 70 { 71 - $orderItem = factory(OrderItem::class)->states('username_change')->create([ 72 - 'order_id' => $this->order->order_id, 71 + $orderItem = OrderItem::factory()->usernameChange()->create([ 72 + 'order_id' => $this->order, 73 73 'extra_info' => $this->user->username, 74 74 ]); 75 75 ··· 81 81 82 82 public function testRunWhenInsuffientPaid() 83 83 { 84 - $orderItem = factory(OrderItem::class)->states('username_change')->create([ 85 - 'order_id' => $this->order->order_id, 84 + $orderItem = OrderItem::factory()->usernameChange()->create([ 85 + 'order_id' => $this->order, 86 86 'cost' => 1, 87 87 'extra_info' => 'new_username', 88 88 ]); ··· 107 107 'user_lastvisit' => time(), 108 108 ]); 109 109 110 - $orderItem = factory(OrderItem::class)->states('username_change')->create([ 111 - 'order_id' => $this->order->order_id, 110 + $orderItem = OrderItem::factory()->usernameChange()->create([ 111 + 'order_id' => $this->order, 112 112 'extra_info' => 'new_username', 113 113 ]); 114 114 ··· 123 123 parent::setUp(); 124 124 125 125 $this->user = User::factory()->create(['osu_subscriptionexpiry' => now()]); 126 - $this->order = factory(Order::class)->states('paid')->create(['user_id' => $this->user->user_id]); 126 + $this->order = Order::factory()->paid()->create(['user_id' => $this->user]); 127 127 } 128 128 }
+22 -22
tests/Libraries/OrderCheckoutTest.php
··· 22 22 { 23 23 $tournament = Tournament::factory()->create(); 24 24 $product = $this->createTournamentProduct($tournament, Carbon::now()->addDays(1)); 25 - $orderItem = factory(OrderItem::class)->create([ 26 - 'product_id' => $product->product_id, 25 + $orderItem = OrderItem::factory()->create([ 26 + 'product_id' => $product, 27 27 'extra_data' => [ 28 28 'tournament_id' => $tournament->getKey(), 29 29 ], ··· 39 39 { 40 40 $tournament = Tournament::factory()->create(); 41 41 $product = $this->createTournamentProduct($tournament); 42 - $orderItem = factory(OrderItem::class)->create([ 43 - 'product_id' => $product->product_id, 42 + $orderItem = OrderItem::factory()->create([ 43 + 'product_id' => $product, 44 44 'extra_data' => [ 45 45 'tournament_id' => $tournament->getKey(), 46 46 ], ··· 56 56 { 57 57 $tournament = Tournament::factory()->create(); 58 58 $product = $this->createTournamentProduct($tournament, Carbon::now()->subDays(1)); 59 - $orderItem = factory(OrderItem::class)->create([ 60 - 'product_id' => $product->product_id, 59 + $orderItem = OrderItem::factory()->create([ 60 + 'product_id' => $product, 61 61 'extra_data' => [ 62 62 'tournament_id' => $tournament->getKey(), 63 63 ], ··· 71 71 72 72 public function testShopifyItemDoesNotMix() 73 73 { 74 - $product1 = factory(Product::class)->create(['stock' => 5, 'max_quantity' => 5, 'shopify_id' => 1]); 75 - $product2 = factory(Product::class)->create(['stock' => 5, 'max_quantity' => 5, 'shopify_id' => null]); 76 - $orderItem1 = factory(OrderItem::class)->create([ 77 - 'product_id' => $product1->product_id, 74 + $product1 = Product::factory()->create(['stock' => 5, 'max_quantity' => 5, 'shopify_id' => 1]); 75 + $product2 = Product::factory()->create(['stock' => 5, 'max_quantity' => 5, 'shopify_id' => null]); 76 + $orderItem1 = OrderItem::factory()->create([ 77 + 'product_id' => $product1, 78 78 'quantity' => 1, 79 79 ]); 80 80 81 - $orderItem2 = factory(OrderItem::class)->create([ 82 - 'product_id' => $product2->product_id, 81 + $orderItem2 = OrderItem::factory()->create([ 82 + 'product_id' => $product2, 83 83 'quantity' => 1, 84 84 ]); 85 85 86 - $order = factory(Order::class)->create(); 86 + $order = Order::factory()->create(); 87 87 $order->items()->save($orderItem1); 88 88 $order->items()->save($orderItem2); 89 89 ··· 98 98 99 99 public function testTotalNonZeroDoesNotAllowFreeCheckout() 100 100 { 101 - $product1 = factory(Product::class)->create(['stock' => 5, 'max_quantity' => 5, 'cost' => 1]); 102 - $orderItem1 = factory(OrderItem::class)->create([ 103 - 'product_id' => $product1->product_id, 101 + $product1 = Product::factory()->create(['stock' => 5, 'max_quantity' => 5, 'cost' => 1]); 102 + $orderItem1 = OrderItem::factory()->create([ 103 + 'product_id' => $product1, 104 104 'quantity' => 1, 105 105 'cost' => $product1->cost, 106 106 ]); 107 107 108 - $order = factory(Order::class)->create(); 108 + $order = Order::factory()->create(); 109 109 $order->items()->save($orderItem1); 110 110 111 111 $checkout = new OrderCheckout($order, Order::PROVIDER_FREE); ··· 119 119 120 120 public function testTotalZeroOnlyAllowsFreeCheckout() 121 121 { 122 - $product1 = factory(Product::class)->create(['stock' => 5, 'max_quantity' => 5, 'cost' => 0]); 123 - $orderItem1 = factory(OrderItem::class)->create([ 124 - 'product_id' => $product1->product_id, 122 + $product1 = Product::factory()->create(['stock' => 5, 'max_quantity' => 5, 'cost' => 0]); 123 + $orderItem1 = OrderItem::factory()->create([ 124 + 'product_id' => $product1, 125 125 'quantity' => 1, 126 126 'cost' => $product1->cost, 127 127 ]); 128 128 129 - $order = factory(Order::class)->create(); 129 + $order = Order::factory()->create(); 130 130 $order->items()->save($orderItem1); 131 131 $checkout = new OrderCheckout($order, Order::PROVIDER_PAYPAL); 132 132 $result = $checkout->allowedCheckoutProviders(); ··· 141 141 { 142 142 $country = Country::inRandomOrder()->first() ?? Country::factory()->create(); 143 143 144 - $product = factory(Product::class)->states('child_banners')->create([ 144 + $product = Product::factory()->childBanners()->create([ 145 145 'available_until' => $availableUntil, 146 146 'name' => "{$tournament->name} Support Banner ({$country->name})", 147 147 ]);
+2 -2
tests/Libraries/Payments/CentiliPaymentProcessorTest.php
··· 67 67 68 68 public function testWhenPaymentIsInsufficient() 69 69 { 70 - $orderItem = factory(OrderItem::class)->states('supporter_tag')->create(['order_id' => $this->order->order_id]); 70 + $orderItem = OrderItem::factory()->supporterTag()->create(['order_id' => $this->order]); 71 71 72 72 $params = $this->getTestParams(['enduserprice' => '479.000']); 73 73 $subject = new CentiliPaymentProcessor($params, $this->validSignature()); ··· 138 138 parent::setUp(); 139 139 Config::set('payments.centili.api_key', 'api_key'); 140 140 Config::set('payments.centili.conversion_rate', 120.00); 141 - $this->order = factory(Order::class)->states('checkout')->create(); 141 + $this->order = Order::factory()->checkout()->create(); 142 142 } 143 143 144 144 private function getTestParams(array $overrides = [])
+2 -2
tests/Libraries/Payments/PaymentProcessorTest.php
··· 81 81 82 82 config()->set('store.order.prefix', 'test'); 83 83 84 - $this->order = factory(Order::class)->states('checkout')->create([ 84 + $this->order = Order::factory()->checkout()->create([ 85 85 'transaction_id' => 'test-123', 86 86 ]); 87 - factory(OrderItem::class)->states('supporter_tag')->create(['order_id' => $this->order->getKey()]); 87 + OrderItem::factory()->supporterTag()->create(['order_id' => $this->order]); 88 88 89 89 $this->subject = new PaymentProcessor([ 90 90 'countryCode' => 'CC',
+4 -4
tests/Libraries/Payments/XsollaPaymentProcessorTest.php
··· 27 27 28 28 public function testWhenPaymentIsInsufficient() 29 29 { 30 - $orderItem = factory(OrderItem::class)->states('supporter_tag')->create(['order_id' => $this->order->order_id]); 30 + $orderItem = OrderItem::factory()->supporterTag()->create(['order_id' => $this->order]); 31 31 32 32 $params = $this->getTestParams([ 33 33 'purchase' => [ ··· 97 97 98 98 public function testWhenOrderProcessingState() 99 99 { 100 - $this->order = factory(Order::class)->states('processing')->create(); 100 + $this->order = Order::factory()->processing()->create(); 101 101 $params = $this->getTestParams(); 102 102 $subject = new XsollaPaymentProcessor($params, $this->validSignature()); 103 103 $subject->run(); ··· 107 107 108 108 public function testWhenOrderHasPhysicalItems() 109 109 { 110 - $orderItem = factory(OrderItem::class)->create(['order_id' => $this->order->order_id]); 110 + $orderItem = OrderItem::factory()->create(['order_id' => $this->order]); 111 111 112 112 $params = $this->getTestParams(); 113 113 $subject = new XsollaPaymentProcessor($params, $this->validSignature()); ··· 124 124 { 125 125 parent::setUp(); 126 126 Config::set('payments.xsolla.api_key', 'api_key'); 127 - $this->order = factory(Order::class)->states('checkout')->create(); 127 + $this->order = Order::factory()->checkout()->create(); 128 128 } 129 129 130 130 private function getTestParams(array $overrides = [])
+3 -3
tests/Models/Store/OrderItemTest.php
··· 115 115 116 116 private function createProductAndOrderItem(int $stock, bool $reserved) 117 117 { 118 - $product = factory(Product::class)->create(['stock' => $stock, 'max_quantity' => 5]); 119 - $orderItem = factory(OrderItem::class)->create([ 120 - 'product_id' => $product->getKey(), 118 + $product = Product::factory()->create(['stock' => $stock, 'max_quantity' => 5]); 119 + $orderItem = OrderItem::factory()->create([ 120 + 'product_id' => $product, 121 121 'quantity' => 2, 122 122 'reserved' => $reserved, 123 123 ]);
+12 -12
tests/Models/Store/OrderTest.php
··· 14 14 { 15 15 public function testContainsSupporterTag() 16 16 { 17 - $order = factory(Order::class)->create(); 18 - $product = factory(Product::class)->create(); 19 - factory(OrderItem::class)->create(['order_id' => $order, 'product_id' => $product]); 20 - factory(OrderItem::class)->states('supporter_tag')->create(['order_id' => $order]); 17 + $order = Order::factory()->create(); 18 + $product = Product::factory()->create(); 19 + OrderItem::factory()->create(['order_id' => $order, 'product_id' => $product]); 20 + OrderItem::factory()->supporterTag()->create(['order_id' => $order]); 21 21 22 22 $this->assertTrue($order->containsSupporterTag()); 23 23 } 24 24 25 25 public function testIsHideSupporterFromActivity() 26 26 { 27 - $order = factory(Order::class)->create(); 28 - factory(OrderItem::class, 2)->states('supporter_tag')->create(['order_id' => $order]); 27 + $order = Order::factory()->create(); 28 + OrderItem::factory()->count(2)->supporterTag()->create(['order_id' => $order]); 29 29 30 30 $this->assertFalse($order->isHideSupporterFromActivity()); 31 31 ··· 37 37 38 38 public function testSetGiftsHidden() 39 39 { 40 - $order = factory(Order::class)->create(); 41 - factory(OrderItem::class, 2)->states('supporter_tag')->create(['order_id' => $order]); 40 + $order = Order::factory()->create(); 41 + OrderItem::factory()->count(2)->supporterTag()->create(['order_id' => $order]); 42 42 43 43 $order->setGiftsHidden(true); 44 44 OrderItem::each(fn ($item) => $this->assertTrue($item->extra_data->hidden)); ··· 49 49 50 50 public function testSwitchOrderItemReservation() 51 51 { 52 - $product1 = factory(Product::class)->create(['stock' => 5, 'max_quantity' => 5]); 53 - $product2 = factory(Product::class)->create(['stock' => 5, 'max_quantity' => 5]); 54 - $orderItem = factory(OrderItem::class)->create([ 55 - 'product_id' => $product1->product_id, 52 + $product1 = Product::factory()->create(['stock' => 5, 'max_quantity' => 5]); 53 + $product2 = Product::factory()->create(['stock' => 5, 'max_quantity' => 5]); 54 + $orderItem = OrderItem::factory()->create([ 55 + 'product_id' => $product1, 56 56 'quantity' => 2, 57 57 'reserved' => true, 58 58 ]);