From c15746935fdae858eafdf629556199930a1747e4 Mon Sep 17 00:00:00 2001 From: iamgergo Date: Mon, 29 Mar 2021 10:12:46 +0200 Subject: [PATCH] use the HasFactory trait --- .../2020_01_01_000000_extend_users_table.php | 9 ++--- src/Models/Address.php | 14 +++++++- src/Models/Cart.php | 14 +++++++- src/Models/Category.php | 14 +++++++- src/Models/Medium.php | 14 +++++++- src/Models/Order.php | 14 +++++++- src/Models/Product.php | 18 ++++++++-- src/Models/Shipping.php | 14 +++++++- src/Models/Transaction.php | 14 +++++++- src/Models/User.php | 14 +++++++- src/Models/Variant.php | 16 +++++++-- tests/Feature/AddressesTest.php | 8 +++-- tests/Feature/CartDriverTest.php | 8 ++--- tests/Feature/CategoriesTest.php | 5 ++- tests/Feature/CheckoutTest.php | 20 +++++------ tests/Feature/ConversionDriverTest.php | 5 ++- tests/Feature/DownloadTest.php | 12 +++---- tests/Feature/GatewayDriverTest.php | 11 +++---- tests/Feature/MediaTest.php | 3 +- tests/Feature/OrdersTest.php | 18 +++++----- tests/Feature/ProductsTest.php | 5 ++- tests/Feature/ShippingDriverTest.php | 4 +-- tests/Feature/TransactionsTest.php | 22 ++++++------- tests/Feature/UsersTest.php | 3 +- tests/Feature/VariantsTest.php | 9 +++-- tests/Feature/WidgetsTest.php | 4 +-- tests/TestCase.php | 5 ++- tests/Unit/AddressTest.php | 33 +++++++++---------- tests/Unit/BazarTest.php | 3 +- tests/Unit/CartTest.php | 19 +++++------ tests/Unit/CategoryTest.php | 12 +++---- tests/Unit/DiscountRepositoryTest.php | 8 ++--- tests/Unit/ImageTest.php | 12 +++---- tests/Unit/ItemTest.php | 4 +-- tests/Unit/JobTest.php | 3 +- tests/Unit/MediumTest.php | 4 +-- tests/Unit/NotificationTest.php | 6 ++-- tests/Unit/OrderTest.php | 18 +++++----- tests/Unit/ProductTest.php | 24 +++++++------- tests/Unit/ShippingTest.php | 19 +++++------ tests/Unit/TaxRepositoryTest.php | 8 ++--- tests/Unit/TransactionTest.php | 8 ++--- tests/Unit/UserTest.php | 12 +++---- tests/Unit/ValidationTest.php | 12 +++---- tests/Unit/VariantTest.php | 10 +++--- 45 files changed, 305 insertions(+), 207 deletions(-) diff --git a/database/migrations/2020_01_01_000000_extend_users_table.php b/database/migrations/2020_01_01_000000_extend_users_table.php index 363a71f1..da39405c 100644 --- a/database/migrations/2020_01_01_000000_extend_users_table.php +++ b/database/migrations/2020_01_01_000000_extend_users_table.php @@ -1,6 +1,5 @@ getDeletedAtColumn(); - - Schema::table('users', static function (Blueprint $table) use ($column): void { - if (! Schema::hasColumn('users', $column)) { - $table->softDeletes($column); + Schema::table('users', static function (Blueprint $table): void { + if (! Schema::hasColumn('users', 'deleted_at')) { + $table->softDeletes(); } }); } diff --git a/src/Models/Address.php b/src/Models/Address.php index afdb2157..eafb097c 100644 --- a/src/Models/Address.php +++ b/src/Models/Address.php @@ -6,15 +6,17 @@ use Bazar\Concerns\Filterable; use Bazar\Concerns\InteractsWithProxy; use Bazar\Contracts\Models\Address as Contract; +use Bazar\Database\Factories\AddressFactory; use Bazar\Support\Countries; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\MorphTo; use Illuminate\Http\Request; class Address extends Model implements Contract { - use BazarRoutable, Filterable, InteractsWithProxy; + use BazarRoutable, Filterable, HasFactory, InteractsWithProxy; /** * The accessors to append to the model's array form. @@ -97,6 +99,16 @@ public static function getProxiedContract(): string return Contract::class; } + /** + * Create a new factory instance for the model. + * + * @return \Illuminate\Database\Eloquent\Factories\Factory + */ + protected static function newFactory(): AddressFactory + { + return AddressFactory::new(); + } + /** * Get the addressable model for the address. * diff --git a/src/Models/Cart.php b/src/Models/Cart.php index 8f85fd1c..c79b3e59 100644 --- a/src/Models/Cart.php +++ b/src/Models/Cart.php @@ -9,13 +9,15 @@ use Bazar\Concerns\InteractsWithItems; use Bazar\Concerns\InteractsWithProxy; use Bazar\Contracts\Models\Cart as Contract; +use Bazar\Database\Factories\CartFactory; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Carbon; class Cart extends Model implements Contract { - use Addressable, HasUuid, InteractsWithDiscounts, InteractsWithItems, InteractsWithProxy; + use Addressable, HasFactory, HasUuid, InteractsWithDiscounts, InteractsWithItems, InteractsWithProxy; /** * The attributes that should have default values. @@ -100,6 +102,16 @@ public static function getProxiedContract(): string return Contract::class; } + /** + * Create a new factory instance for the model. + * + * @return \Illuminate\Database\Eloquent\Factories\Factory + */ + protected static function newFactory(): CartFactory + { + return CartFactory::new(); + } + /** * Lock the cart. * diff --git a/src/Models/Category.php b/src/Models/Category.php index 7f37746a..6f18a5ef 100644 --- a/src/Models/Category.php +++ b/src/Models/Category.php @@ -8,7 +8,9 @@ use Bazar\Concerns\InteractsWithProxy; use Bazar\Concerns\Sluggable; use Bazar\Contracts\Models\Category as Contract; +use Bazar\Database\Factories\CategoryFactory; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\SoftDeletes; @@ -16,7 +18,7 @@ class Category extends Model implements Contract { - use BazarRoutable, Filterable, HasMedia, InteractsWithProxy, Sluggable, SoftDeletes; + use BazarRoutable, Filterable, HasFactory, HasMedia, InteractsWithProxy, Sluggable, SoftDeletes; /** * The attributes that are mass assignable. @@ -55,6 +57,16 @@ public static function getProxiedContract(): string return Contract::class; } + /** + * Create a new factory instance for the model. + * + * @return \Illuminate\Database\Eloquent\Factories\Factory + */ + protected static function newFactory(): CategoryFactory + { + return CategoryFactory::new(); + } + /** * Get the products for the category. * diff --git a/src/Models/Medium.php b/src/Models/Medium.php index 816849d0..b02264b0 100644 --- a/src/Models/Medium.php +++ b/src/Models/Medium.php @@ -5,8 +5,10 @@ use Bazar\Concerns\Filterable; use Bazar\Concerns\InteractsWithProxy; use Bazar\Contracts\Models\Medium as Contract; +use Bazar\Database\Factories\MediumFactory; use Bazar\Support\Facades\Conversion; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Storage; @@ -15,7 +17,7 @@ class Medium extends Model implements Contract { - use Filterable, InteractsWithProxy; + use Filterable, HasFactory, InteractsWithProxy; /** * The accessors to append to the model's array form. @@ -90,6 +92,16 @@ public static function getProxiedContract(): string return Contract::class; } + /** + * Create a new factory instance for the model. + * + * @return \Illuminate\Database\Eloquent\Factories\Factory + */ + protected static function newFactory(): MediumFactory + { + return MediumFactory::new(); + } + /** * Create a new medium from the given path. * diff --git a/src/Models/Order.php b/src/Models/Order.php index 9ae5f95f..496012fd 100644 --- a/src/Models/Order.php +++ b/src/Models/Order.php @@ -10,7 +10,9 @@ use Bazar\Concerns\InteractsWithItems; use Bazar\Concerns\InteractsWithProxy; use Bazar\Contracts\Models\Order as Contract; +use Bazar\Database\Factories\OrderFactory; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; @@ -19,7 +21,7 @@ class Order extends Model implements Contract { - use Addressable, BazarRoutable, Filterable, InteractsWithDiscounts, InteractsWithItems, InteractsWithProxy, SoftDeletes; + use Addressable, BazarRoutable, Filterable, HasFactory, InteractsWithDiscounts, InteractsWithItems, InteractsWithProxy, SoftDeletes; /** * The accessors to append to the model's array form. @@ -85,6 +87,16 @@ public static function getProxiedContract(): string return Contract::class; } + /** + * Create a new factory instance for the model. + * + * @return \Illuminate\Database\Eloquent\Factories\Factory + */ + protected static function newFactory(): OrderFactory + { + return OrderFactory::new(); + } + /** * Create a new order from the given cart. * diff --git a/src/Models/Product.php b/src/Models/Product.php index a785a67f..15b45798 100644 --- a/src/Models/Product.php +++ b/src/Models/Product.php @@ -11,7 +11,9 @@ use Bazar\Concerns\InteractsWithStock; use Bazar\Concerns\Sluggable; use Bazar\Contracts\Models\Product as Contract; +use Bazar\Database\Factories\ProductFactory; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; @@ -23,7 +25,7 @@ class Product extends Model implements Contract { - use BazarRoutable, Filterable, InteractsWithProxy, InteractsWithStock, HasMedia, Sluggable, SoftDeletes; + use BazarRoutable, Filterable, HasFactory, InteractsWithProxy, InteractsWithStock, HasMedia, Sluggable, SoftDeletes; /** * The accessors to append to the model's array form. @@ -42,8 +44,8 @@ class Product extends Model implements Contract */ protected $attributes = [ 'prices' => '[]', - 'properties' => '[]', 'inventory' => '[]', + 'properties' => '[]', ]; /** @@ -66,8 +68,8 @@ class Product extends Model implements Contract 'name', 'slug', 'prices', - 'properties', 'inventory', + 'properties', 'description', ]; @@ -88,6 +90,16 @@ public static function getProxiedContract(): string return Contract::class; } + /** + * Create a new factory instance for the model. + * + * @return \Illuminate\Database\Eloquent\Factories\Factory + */ + protected static function newFactory(): ProductFactory + { + return ProductFactory::new(); + } + /** * Get the filter options for the model. * diff --git a/src/Models/Shipping.php b/src/Models/Shipping.php index 60cae6b6..c0381919 100644 --- a/src/Models/Shipping.php +++ b/src/Models/Shipping.php @@ -6,7 +6,9 @@ use Bazar\Concerns\InteractsWithProxy; use Bazar\Concerns\InteractsWithTaxes; use Bazar\Contracts\Models\Shipping as Contract; +use Bazar\Database\Factories\ShippingFactory; use Bazar\Support\Facades\Shipping as Manager; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\MorphTo; use Illuminate\Support\Str; @@ -14,7 +16,7 @@ class Shipping extends Model implements Contract { - use Addressable, InteractsWithProxy, InteractsWithTaxes; + use Addressable, HasFactory, InteractsWithProxy, InteractsWithTaxes; /** * The accessors to append to the model's array form. @@ -75,6 +77,16 @@ public static function getProxiedContract(): string return Contract::class; } + /** + * Create a new factory instance for the model. + * + * @return \Illuminate\Database\Eloquent\Factories\Factory + */ + protected static function newFactory(): ShippingFactory + { + return ShippingFactory::new(); + } + /** * Get the shippable model for the shipping. * diff --git a/src/Models/Transaction.php b/src/Models/Transaction.php index e889b8f3..2a949ade 100644 --- a/src/Models/Transaction.php +++ b/src/Models/Transaction.php @@ -4,9 +4,11 @@ use Bazar\Concerns\InteractsWithProxy; use Bazar\Contracts\Models\Transaction as Contract; +use Bazar\Database\Factories\TransactionFactory; use Bazar\Support\Facades\Gateway; use DateTimeInterface; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Support\Carbon; @@ -14,7 +16,7 @@ class Transaction extends Model implements Contract { - use InteractsWithProxy; + use HasFactory, InteractsWithProxy; /** * The accessors to append to the model's array form. @@ -64,6 +66,16 @@ public static function getProxiedContract(): string return Contract::class; } + /** + * Create a new factory instance for the model. + * + * @return \Illuminate\Database\Eloquent\Factories\Factory + */ + protected static function newFactory(): TransactionFactory + { + return TransactionFactory::new(); + } + /** * Get the order for the transaction. * diff --git a/src/Models/User.php b/src/Models/User.php index 10e0160c..c3157c0d 100644 --- a/src/Models/User.php +++ b/src/Models/User.php @@ -6,8 +6,10 @@ use Bazar\Concerns\Filterable; use Bazar\Concerns\InteractsWithProxy; use Bazar\Contracts\Models\User as Contract; +use Bazar\Database\Factories\UserFactory; use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\Relations\MorphMany; @@ -22,7 +24,7 @@ class User extends Authenticatable implements Contract, MustVerifyEmail { - use BazarRoutable, Filterable, InteractsWithProxy, Notifiable, SoftDeletes; + use BazarRoutable, Filterable, HasFactory, InteractsWithProxy, Notifiable, SoftDeletes; /** * The accessors to append to the model's array form. @@ -96,6 +98,16 @@ public static function getProxiedContract(): string return Contract::class; } + /** + * Create a new factory instance for the model. + * + * @return \Illuminate\Database\Eloquent\Factories\Factory + */ + protected static function newFactory(): UserFactory + { + return UserFactory::new(); + } + /** * Get the filter options for the model. * diff --git a/src/Models/Variant.php b/src/Models/Variant.php index 17966452..a7a32275 100644 --- a/src/Models/Variant.php +++ b/src/Models/Variant.php @@ -11,7 +11,9 @@ use Bazar\Concerns\InteractsWithProxy; use Bazar\Concerns\InteractsWithStock; use Bazar\Contracts\Models\Variant as Contract; +use Bazar\Database\Factories\VariantFactory; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; @@ -19,7 +21,7 @@ class Variant extends Model implements Contract { - use BazarRoutable, Filterable, InteractsWithProxy, InteractsWithStock, HasMedia, SoftDeletes; + use BazarRoutable, Filterable, HasFactory, HasMedia, InteractsWithProxy, InteractsWithStock, SoftDeletes; /** * The accessors to append to the model's array form. @@ -60,9 +62,9 @@ class Variant extends Model implements Contract */ protected $fillable = [ 'alias', - 'variation', 'prices', 'inventory', + 'variation', ]; /** @@ -82,6 +84,16 @@ public static function getProxiedContract(): string return Contract::class; } + /** + * Create a new factory instance for the model. + * + * @return \Illuminate\Database\Eloquent\Factories\Factory + */ + protected static function newFactory(): VariantFactory + { + return VariantFactory::new(); + } + /** * Get the product for the transaction. * diff --git a/tests/Feature/AddressesTest.php b/tests/Feature/AddressesTest.php index 83d88827..a5755871 100644 --- a/tests/Feature/AddressesTest.php +++ b/tests/Feature/AddressesTest.php @@ -2,7 +2,7 @@ namespace Bazar\Tests\Feature; -use Bazar\Database\Factories\AddressFactory; +use Bazar\Models\Address; use Bazar\Tests\TestCase; use Illuminate\Support\Facades\URL; @@ -14,7 +14,9 @@ public function setUp(): void { parent::setUp(); - $this->address = $this->user->addresses()->save(AddressFactory::new()->make()); + $this->address = $this->user->addresses()->save( + Address::factory()->make() + ); } /** @test */ @@ -54,7 +56,7 @@ public function an_admin_can_store_address() $this->actingAs($this->admin)->post( URL::route('bazar.users.addresses.store', $this->user), - AddressFactory::new()->make(['first_name' => 'Test'])->toArray() + Address::factory()->make(['first_name' => 'Test'])->toArray() )->assertRedirect(URL::route('bazar.users.addresses.show', [ $this->user, $this->user->fresh()->addresses->reverse()->first() diff --git a/tests/Feature/CartDriverTest.php b/tests/Feature/CartDriverTest.php index 9a0b105d..de157e4d 100644 --- a/tests/Feature/CartDriverTest.php +++ b/tests/Feature/CartDriverTest.php @@ -5,11 +5,11 @@ use Bazar\Cart\Checkout; use Bazar\Cart\CookieDriver; use Bazar\Cart\Manager; -use Bazar\Database\Factories\ProductFactory; -use Bazar\Database\Factories\VariantFactory; use Bazar\Events\CartTouched; use Bazar\Models\Cart; +use Bazar\Models\Product; use Bazar\Models\Shipping; +use Bazar\Models\Variant; use Bazar\Support\Facades\Cart as CartFacade; use Bazar\Tests\TestCase; use Illuminate\Support\Facades\Event; @@ -23,8 +23,8 @@ public function setUp(): void parent::setUp(); $this->manager = $this->app->make(Manager::class); - $this->product = ProductFactory::new()->create(['prices' => ['usd' => ['default' => 100]]]); - $this->variant = $this->product->variants()->save(VariantFactory::new()->make([ + $this->product = Product::factory()->create(['prices' => ['usd' => ['default' => 100]]]); + $this->variant = $this->product->variants()->save(Variant::factory()->make([ 'variation' => ['Size' => 'S'], 'prices' => ['usd' => ['default' => 150]], ])); diff --git a/tests/Feature/CategoriesTest.php b/tests/Feature/CategoriesTest.php index 9a40dada..b8aa16cb 100644 --- a/tests/Feature/CategoriesTest.php +++ b/tests/Feature/CategoriesTest.php @@ -2,7 +2,6 @@ namespace Bazar\Tests\Feature; -use Bazar\Database\Factories\CategoryFactory; use Bazar\Models\Category; use Bazar\Tests\TestCase; use Illuminate\Support\Facades\URL; @@ -15,7 +14,7 @@ public function setUp(): void { parent::setUp(); - $this->category = CategoryFactory::new()->create(); + $this->category = Category::factory()->create(); } /** @test */ @@ -61,7 +60,7 @@ public function an_admin_can_store_category() $this->actingAs($this->admin)->post( URL::route('bazar.categories.store'), - CategoryFactory::new()->make(['name' => 'Test'])->toArray() + Category::factory()->make(['name' => 'Test'])->toArray() )->assertRedirect(URL::route('bazar.categories.show', Category::find(2))); $this->assertDatabaseHas('bazar_categories', ['name' => 'Test']); diff --git a/tests/Feature/CheckoutTest.php b/tests/Feature/CheckoutTest.php index 48da60a8..980c88ff 100644 --- a/tests/Feature/CheckoutTest.php +++ b/tests/Feature/CheckoutTest.php @@ -2,12 +2,12 @@ namespace Bazar\Tests\Feature; -use Bazar\Database\Factories\AddressFactory; -use Bazar\Database\Factories\CartFactory; -use Bazar\Database\Factories\ProductFactory; +use Bazar\Cart\Checkout; +use Bazar\Models\Address; +use Bazar\Models\Cart; +use Bazar\Models\Product; use Bazar\Notifications\AdminNewOrder; use Bazar\Notifications\CustomerNewOrder; -use Bazar\Cart\Checkout; use Bazar\Tests\TestCase; use Illuminate\Notifications\AnonymousNotifiable; use Illuminate\Support\Facades\Notification; @@ -20,10 +20,10 @@ public function setUp(): void { parent::setUp(); - $this->cart = CartFactory::new()->create(); + $this->cart = Cart::factory()->create(); $this->cart->products()->attach( - ProductFactory::new()->count(3)->create()->mapWithKeys(function ($product) { + Product::factory()->count(3)->create()->mapWithKeys(function ($product) { [$quantity, $tax, $price] = [mt_rand(1, 5), 0, $product->price]; return [$product->id => compact('price', 'tax', 'quantity')]; @@ -37,9 +37,9 @@ public function it_can_process_checkout() Notification::fake(); $response = (new Checkout($this->cart))->shipping( - 'local-pickup', AddressFactory::new()->make()->toArray() + 'local-pickup', Address::factory()->make()->toArray() )->billing( - AddressFactory::new()->make()->toArray() + Address::factory()->make()->toArray() )->gateway('cash')->onSuccess(function ($order) { return 'Success'; })->onFailure(function ($e, $order) { @@ -62,9 +62,9 @@ function ($notification, $channels, $notifiable) { public function it_handles_failed_checkout() { $response = (new Checkout($this->cart))->shipping( - 'local-pickup', AddressFactory::new()->make()->toArray() + 'local-pickup', Address::factory()->make()->toArray() )->billing( - AddressFactory::new()->make()->toArray() + Address::factory()->make()->toArray() )->gateway('fake')->onSuccess(function ($order) { // })->onFailure(function ($e, $order) { diff --git a/tests/Feature/ConversionDriverTest.php b/tests/Feature/ConversionDriverTest.php index 460190d0..c1b4d882 100644 --- a/tests/Feature/ConversionDriverTest.php +++ b/tests/Feature/ConversionDriverTest.php @@ -3,9 +3,8 @@ namespace Bazar\Tests\Feature; use Bazar\Contracts\Conversion\Manager; -use Bazar\Models\Medium; use Bazar\Conversion\GdDriver; -use Bazar\Database\Factories\MediumFactory; +use Bazar\Models\Medium; use Bazar\Support\Facades\Conversion; use Bazar\Tests\TestCase; use Illuminate\Http\UploadedFile; @@ -52,7 +51,7 @@ public function it_can_remove_conversions() /** @test */ public function it_can_perform_conversions() { - $medium = MediumFactory::new()->create([ + $medium = Medium::factory()->create([ 'name' => 'test', 'file_name' => 'test.png', 'mime_type' => 'image/png', diff --git a/tests/Feature/DownloadTest.php b/tests/Feature/DownloadTest.php index 0c64dd23..5769d38e 100644 --- a/tests/Feature/DownloadTest.php +++ b/tests/Feature/DownloadTest.php @@ -2,9 +2,9 @@ namespace Bazar\Tests\Feature; -use Bazar\Database\Factories\MediumFactory; -use Bazar\Database\Factories\OrderFactory; -use Bazar\Database\Factories\ProductFactory; +use Bazar\Models\Medium; +use Bazar\Models\Order; +use Bazar\Models\Product; use Bazar\Tests\TestCase; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\URL; @@ -17,10 +17,10 @@ public function setUp(): void { parent::setUp(); - $medium = MediumFactory::new()->create(); + $medium = Medium::factory()->create(); Storage::disk($medium->disk)->put($medium->path(), 'fake content'); - $product = ProductFactory::new()->create([ + $product = Product::factory()->create([ 'inventory' => [ 'downloadable' => true, 'files' => [ @@ -30,7 +30,7 @@ public function setUp(): void ], ]); - $this->order = OrderFactory::new()->create(); + $this->order = Order::factory()->create(); $this->order->products()->attach($product, ['quantity' => 1, 'tax' => 0, 'price' => $product->price]); } diff --git a/tests/Feature/GatewayDriverTest.php b/tests/Feature/GatewayDriverTest.php index 000f6310..b4d38cf0 100644 --- a/tests/Feature/GatewayDriverTest.php +++ b/tests/Feature/GatewayDriverTest.php @@ -2,15 +2,14 @@ namespace Bazar\Tests\Feature; -use Bazar\Models\Order; -use Bazar\Models\Transaction; -use Bazar\Database\Factories\OrderFactory; -use Bazar\Database\Factories\ProductFactory; use Bazar\Exceptions\TransactionFailedException; use Bazar\Gateway\CashDriver; use Bazar\Gateway\Driver; use Bazar\Gateway\Manager; use Bazar\Gateway\TransferDriver; +use Bazar\Models\Order; +use Bazar\Models\Product; +use Bazar\Models\Transaction; use Bazar\Tests\TestCase; use InvalidArgumentException; use Throwable; @@ -23,8 +22,8 @@ public function setUp(): void { parent::setUp(); - $this->order = OrderFactory::new()->create(); - $products = ProductFactory::new()->count(3)->create()->mapWithKeys(function ($product) { + $this->order = Order::factory()->create(); + $products = Product::factory()->count(3)->create()->mapWithKeys(function ($product) { return [$product->id => ['quantity' => mt_rand(1, 5), 'tax' => 0, 'price' => $product->price]]; }); $this->order->products()->attach($products->all()); diff --git a/tests/Feature/MediaTest.php b/tests/Feature/MediaTest.php index 1a24bc11..5759bcd9 100644 --- a/tests/Feature/MediaTest.php +++ b/tests/Feature/MediaTest.php @@ -2,7 +2,6 @@ namespace Bazar\Tests\Feature; -use Bazar\Database\Factories\MediumFactory; use Bazar\Jobs\MoveFile; use Bazar\Jobs\PerformConversions; use Bazar\Models\Medium; @@ -27,7 +26,7 @@ public function setUp(): void Queue::fake(); - $this->medium = MediumFactory::new()->create(); + $this->medium = Medium::factory()->create(); Storage::disk($this->medium->disk)->put($this->medium->path(), 'fake content'); } diff --git a/tests/Feature/OrdersTest.php b/tests/Feature/OrdersTest.php index 5bb858f5..44b777f6 100644 --- a/tests/Feature/OrdersTest.php +++ b/tests/Feature/OrdersTest.php @@ -2,9 +2,7 @@ namespace Bazar\Tests\Feature; -use Bazar\Database\Factories\AddressFactory; -use Bazar\Database\Factories\OrderFactory; -use Bazar\Database\Factories\ProductFactory; +use Bazar\Models\Address; use Bazar\Models\Order; use Bazar\Models\Product; use Bazar\Tests\TestCase; @@ -18,12 +16,12 @@ public function setUp(): void { parent::setUp(); - ProductFactory::new()->create(); + Product::factory()->create(); - $this->order = $this->admin->orders()->save(OrderFactory::new()->make()); - $this->order->address()->save(AddressFactory::new()->make()); + $this->order = $this->admin->orders()->save(Order::factory()->make()); + $this->order->address()->save(Address::factory()->make()); $this->order->shipping->save(); - $this->order->shipping->address()->save(AddressFactory::new()->make()); + $this->order->shipping->address()->save(Address::factory()->make()); } /** @test */ @@ -67,9 +65,9 @@ public function an_admin_can_store_order() ->assertStatus(302) ->assertSessionHasErrors(); - $order = OrderFactory::new()->make(); - $order->setRelation('address', AddressFactory::new()->make()); - $order->shipping->setRelation('address', AddressFactory::new()->make()); + $order = Order::factory()->make(); + $order->setRelation('address', Address::factory()->make()); + $order->shipping->setRelation('address', Address::factory()->make()); $product = Product::first(); diff --git a/tests/Feature/ProductsTest.php b/tests/Feature/ProductsTest.php index 0380a75e..f90c1833 100644 --- a/tests/Feature/ProductsTest.php +++ b/tests/Feature/ProductsTest.php @@ -2,7 +2,6 @@ namespace Bazar\Tests\Feature; -use Bazar\Database\Factories\ProductFactory; use Bazar\Models\Product; use Bazar\Tests\TestCase; use Illuminate\Support\Facades\URL; @@ -15,7 +14,7 @@ public function setUp(): void { parent::setUp(); - $this->product = ProductFactory::new()->create(); + $this->product = Product::factory()->create(); } /** @test */ @@ -60,7 +59,7 @@ public function an_admin_can_store_product() $this->actingAs($this->admin)->post( URL::route('bazar.products.store'), - ProductFactory::new()->make(['name' => 'Test'])->toArray() + Product::factory()->make(['name' => 'Test'])->toArray() )->assertRedirect(URL::route('bazar.products.show', Product::find(2))); $this->assertDatabaseHas('bazar_products', ['name' => 'Test']); diff --git a/tests/Feature/ShippingDriverTest.php b/tests/Feature/ShippingDriverTest.php index 4768dc4e..5d3b16fe 100644 --- a/tests/Feature/ShippingDriverTest.php +++ b/tests/Feature/ShippingDriverTest.php @@ -4,7 +4,7 @@ use Bazar\Contracts\Shippable; use Bazar\Contracts\Shipping\Manager; -use Bazar\Database\Factories\OrderFactory; +use Bazar\Models\Order; use Bazar\Shipping\Driver; use Bazar\Shipping\LocalPickupDriver; use Bazar\Tests\TestCase; @@ -17,7 +17,7 @@ public function setUp(): void { parent::setUp(); - $this->order = OrderFactory::new()->create(); + $this->order = Order::factory()->create(); $this->manager = $this->app->make(Manager::class); $this->manager->extend('custom-driver', function () { diff --git a/tests/Feature/TransactionsTest.php b/tests/Feature/TransactionsTest.php index 09a87731..d234cbed 100644 --- a/tests/Feature/TransactionsTest.php +++ b/tests/Feature/TransactionsTest.php @@ -2,13 +2,11 @@ namespace Bazar\Tests\Feature; -use Bazar\Models\Order; -use Bazar\Models\Transaction; -use Bazar\Database\Factories\OrderFactory; -use Bazar\Database\Factories\ProductFactory; -use Bazar\Database\Factories\TransactionFactory; use Bazar\Exceptions\TransactionFailedException; use Bazar\Gateway\Driver; +use Bazar\Models\Order; +use Bazar\Models\Product; +use Bazar\Models\Transaction; use Bazar\Support\Facades\Gateway; use Bazar\Tests\TestCase; use Illuminate\Support\Facades\URL; @@ -27,9 +25,9 @@ public function setUp(): void 'X-Requested-With' => 'XMLHttpRequest', ]); - $this->order = $this->admin->orders()->save(OrderFactory::new()->make()); + $this->order = $this->admin->orders()->save(Order::factory()->make()); - $this->transaction = $this->order->transactions()->save(TransactionFactory::new()->make([ + $this->transaction = $this->order->transactions()->save(Transaction::factory()->make([ 'amount' => 0, 'type' => 'payment', ])); @@ -43,11 +41,11 @@ public function setUp(): void public function an_admin_can_store_transaction() { $this->order->transactions()->save( - TransactionFactory::new()->make(['driver' => 'fake', 'amount' => 0]) + Transaction::factory()->make(['driver' => 'fake', 'amount' => 0]) ); $this->order->products()->attach( - $product = ProductFactory::new()->create(), + $product = Product::factory()->create(), ['quantity' => 1, 'tax' => 0, 'price' => $product->price], ); @@ -61,7 +59,7 @@ public function an_admin_can_store_transaction() $this->actingAs($this->admin)->post( URL::route('bazar.orders.transactions.store', $this->order), - $payment = TransactionFactory::new()->make([ + $payment = Transaction::factory()->make([ 'type' => 'refund', 'driver' => 'fake', 'amount' => null, @@ -70,7 +68,7 @@ public function an_admin_can_store_transaction() $this->actingAs($this->admin)->post( URL::route('bazar.orders.transactions.store', $this->order), - $payment = TransactionFactory::new()->make([ + $payment = Transaction::factory()->make([ 'type' => 'payment', 'driver' => 'manual', 'amount' => $this->order->fresh()->totalPayable(), @@ -80,7 +78,7 @@ public function an_admin_can_store_transaction() $this->actingAs($this->admin)->post( URL::route('bazar.orders.transactions.store', $this->order), - $refund = TransactionFactory::new()->make([ + $refund = Transaction::factory()->make([ 'type' => 'refund', 'driver' => 'manual', 'amount' => $this->order->totalRefundable(), diff --git a/tests/Feature/UsersTest.php b/tests/Feature/UsersTest.php index 13bcc569..be38e4fd 100644 --- a/tests/Feature/UsersTest.php +++ b/tests/Feature/UsersTest.php @@ -2,7 +2,6 @@ namespace Bazar\Tests\Feature; -use Bazar\Database\Factories\UserFactory; use Bazar\Models\User; use Bazar\Tests\TestCase; use Illuminate\Support\Facades\URL; @@ -51,7 +50,7 @@ public function an_admin_can_store_user() $this->actingAs($this->admin)->post( URL::route('bazar.users.store'), - UserFactory::new()->make(['name' => 'Test'])->toArray() + User::factory()->make(['name' => 'Test'])->toArray() )->assertRedirect(URL::route('bazar.users.show', User::find(3))) ->assertSessionHas('message', 'The user has been created.'); diff --git a/tests/Feature/VariantsTest.php b/tests/Feature/VariantsTest.php index 0f2b3d4c..cfaff30f 100644 --- a/tests/Feature/VariantsTest.php +++ b/tests/Feature/VariantsTest.php @@ -2,8 +2,7 @@ namespace Bazar\Tests\Feature; -use Bazar\Database\Factories\ProductFactory; -use Bazar\Database\Factories\VariantFactory; +use Bazar\Models\Product; use Bazar\Models\Variant; use Bazar\Tests\TestCase; use Illuminate\Support\Facades\URL; @@ -16,8 +15,8 @@ public function setUp(): void { parent::setUp(); - $this->product = ProductFactory::new()->create(); - $this->variant = $this->product->variants()->save(VariantFactory::new()->make()); + $this->product = Product::factory()->create(); + $this->variant = $this->product->variants()->save(Variant::factory()->make()); } /** @test */ @@ -60,7 +59,7 @@ public function an_admin_can_store_variant() $this->actingAs($this->admin)->post( URL::route('bazar.products.variants.store', $this->product), - VariantFactory::new()->make(['variation' => ['Size' => 'M']])->toArray() + Variant::factory()->make(['variation' => ['Size' => 'M']])->toArray() )->assertRedirect(URL::route('bazar.products.variants.show', [$this->product, Variant::find(2)])); $this->assertDatabaseHas('bazar_variants', ['variation->Size' => 'M']); diff --git a/tests/Feature/WidgetsTest.php b/tests/Feature/WidgetsTest.php index 86d2d4db..e3bd23b5 100644 --- a/tests/Feature/WidgetsTest.php +++ b/tests/Feature/WidgetsTest.php @@ -2,7 +2,7 @@ namespace Bazar\Tests\Feature; -use Bazar\Database\Factories\OrderFactory; +use Bazar\Models\Order; use Bazar\Tests\TestCase; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\URL; @@ -13,7 +13,7 @@ public function setUp(): void { parent::setUp(); - OrderFactory::new()->count(3)->create(); + Order::factory()->count(3)->create(); } /** @test */ diff --git a/tests/TestCase.php b/tests/TestCase.php index 40fbcad9..5f85416b 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,7 +2,6 @@ namespace Bazar\Tests; -use Bazar\Database\Factories\UserFactory; use Bazar\Models\Address; use Bazar\Models\Category; use Bazar\Models\Medium; @@ -35,8 +34,8 @@ public function setUp(): void Storage::fake('local'); Storage::fake('public'); - $this->admin = UserFactory::new()->create(['email' => 'test@bazar.test']); - $this->user = UserFactory::new()->create(); + $this->admin = User::factory()->create(['email' => 'test@bazar.test']); + $this->user = User::factory()->create(); } protected function registerPolicies(): void diff --git a/tests/Unit/AddressTest.php b/tests/Unit/AddressTest.php index 7d6f19da..de97137a 100644 --- a/tests/Unit/AddressTest.php +++ b/tests/Unit/AddressTest.php @@ -3,10 +3,7 @@ namespace Bazar\Tests\Unit; use Bazar\Contracts\Breadcrumbable; -use Bazar\Database\Factories\AddressFactory; -use Bazar\Database\Factories\CartFactory; -use Bazar\Database\Factories\OrderFactory; -use Bazar\Database\Factories\ShippingFactory; +use Bazar\Models\Address; use Bazar\Models\Cart; use Bazar\Models\Order; use Bazar\Models\Shipping; @@ -18,7 +15,7 @@ class AddressTest extends TestCase /** @test */ public function it_belongs_to_user() { - $address = AddressFactory::new()->make(); + $address = Address::factory()->make(); $address->addressable()->associate($this->user)->save(); @@ -31,9 +28,9 @@ public function it_belongs_to_user() /** @test */ public function it_belongs_to_cart() { - $address = AddressFactory::new()->make(); + $address = Address::factory()->make(); - $cart = CartFactory::new()->create(); + $cart = Cart::factory()->create(); $address->addressable()->associate($cart)->save(); @@ -46,9 +43,9 @@ public function it_belongs_to_cart() /** @test */ public function it_belongs_to_order() { - $address = AddressFactory::new()->make(); + $address = Address::factory()->make(); - $order = OrderFactory::new()->create(); + $order = Order::factory()->create(); $address->addressable()->associate($order)->save(); @@ -61,12 +58,12 @@ public function it_belongs_to_order() /** @test */ public function it_belongs_to_shipping() { - $address = AddressFactory::new()->make(); + $address = Address::factory()->make(); - $order = OrderFactory::new()->create(); + $order = Order::factory()->create(); $shipping = $order->shipping()->save( - ShippingFactory::new()->make() + Shipping::factory()->make() ); $address->addressable()->associate($shipping)->save(); @@ -80,7 +77,7 @@ public function it_belongs_to_shipping() /** @test */ public function it_has_name_attribute() { - $address = AddressFactory::new()->make(); + $address = Address::factory()->make(); $this->assertSame( sprintf('%s %s', $address->first_name, $address->last_name), @@ -91,7 +88,7 @@ public function it_has_name_attribute() /** @test */ public function it_has_country_name_attribute() { - $address = AddressFactory::new()->make(); + $address = Address::factory()->make(); $this->assertSame( Countries::name($address->country), $address->countryName @@ -101,7 +98,7 @@ public function it_has_country_name_attribute() /** @test */ public function it_has_alias_attribute() { - $address = AddressFactory::new()->make(['alias' => 'Fake']); + $address = Address::factory()->make(['alias' => 'Fake']); $this->assertSame('Fake', $address->alias); @@ -115,7 +112,7 @@ public function it_has_alias_attribute() /** @test */ public function it_has_custom_attribute() { - $address = AddressFactory::new()->make(['custom' => [ + $address = Address::factory()->make(['custom' => [ 'key' => 'value', ]]); @@ -127,7 +124,7 @@ public function it_has_custom_attribute() /** @test */ public function it_is_breadcrumbable() { - $address = $this->user->addresses()->save(AddressFactory::new()->make()); + $address = $this->user->addresses()->save(Address::factory()->make()); $this->assertInstanceOf(Breadcrumbable::class, $address); $this->assertSame($address->alias, $address->toBreadcrumb($this->app['request'])); @@ -136,7 +133,7 @@ public function it_is_breadcrumbable() /** @test */ public function it_has_query_scopes() { - $address = AddressFactory::new()->make(); + $address = Address::factory()->make(); $address->addressable()->associate($this->user)->save(); diff --git a/tests/Unit/BazarTest.php b/tests/Unit/BazarTest.php index 7d1ba7aa..f625fa3d 100644 --- a/tests/Unit/BazarTest.php +++ b/tests/Unit/BazarTest.php @@ -3,7 +3,6 @@ namespace Bazar\Tests\Unit; use Bazar\Bazar; -use Bazar\Database\Factories\ProductFactory; use Bazar\Exceptions\InvalidCurrencyException; use Bazar\Models\Product; use Bazar\Tests\TestCase; @@ -44,7 +43,7 @@ public function it_can_route_bind_soft_deleted_only_for_bazar_routes() // }); - $product = ProductFactory::new()->create(); + $product = Product::factory()->create(); $this->get('shop/products/'.$product->id)->assertOk(); diff --git a/tests/Unit/CartTest.php b/tests/Unit/CartTest.php index 23fceb74..b3679a92 100644 --- a/tests/Unit/CartTest.php +++ b/tests/Unit/CartTest.php @@ -2,11 +2,10 @@ namespace Bazar\Tests\Unit; -use Bazar\Bazar; -use Bazar\Database\Factories\AddressFactory; -use Bazar\Database\Factories\CartFactory; -use Bazar\Database\Factories\ProductFactory; -use Bazar\Database\Factories\ShippingFactory; +use Bazar\Models\Address; +use Bazar\Models\Cart; +use Bazar\Models\Product; +use Bazar\Models\Shipping; use Bazar\Tests\TestCase; use Illuminate\Support\Carbon; @@ -18,9 +17,9 @@ public function setUp(): void { parent::setUp(); - $this->cart = CartFactory::new()->create(); + $this->cart = Cart::factory()->create(); - $this->products = ProductFactory::new()->count(3)->create()->mapWithKeys(function ($product) { + $this->products = Product::factory()->count(3)->create()->mapWithKeys(function ($product) { [$quantity, $tax, $price] = [mt_rand(1, 5), 0, $product->price('sale') ?: $product->price()]; return [$product->id => compact('price', 'tax', 'quantity')]; @@ -44,7 +43,7 @@ public function it_can_belong_to_a_customer() /** @test */ public function it_has_a_shipping() { - $shipping = $this->cart->shipping()->save(ShippingFactory::new()->make()); + $shipping = $this->cart->shipping()->save(Shipping::factory()->make()); $this->assertSame($shipping->id, $this->cart->shipping->id); } @@ -53,7 +52,7 @@ public function it_has_a_shipping() public function it_has_address() { $address = $this->cart->address()->save( - AddressFactory::new()->make() + Address::factory()->make() ); $this->assertSame($address->id, $this->cart->address->id); @@ -62,7 +61,7 @@ public function it_has_address() /** @test */ public function it_has_products() { - $product = ProductFactory::new()->create(); + $product = Product::factory()->create(); $this->cart->products()->attach($product, [ 'price' => 100, 'tax' => 0, 'quantity' => 3, diff --git a/tests/Unit/CategoryTest.php b/tests/Unit/CategoryTest.php index 04d6d0b3..c56ba630 100644 --- a/tests/Unit/CategoryTest.php +++ b/tests/Unit/CategoryTest.php @@ -3,9 +3,9 @@ namespace Bazar\Tests\Unit; use Bazar\Contracts\Breadcrumbable; -use Bazar\Database\Factories\CategoryFactory; -use Bazar\Database\Factories\MediumFactory; -use Bazar\Database\Factories\ProductFactory; +use Bazar\Models\Category; +use Bazar\Models\Medium; +use Bazar\Models\Product; use Bazar\Tests\TestCase; class CategoryTest extends TestCase @@ -16,13 +16,13 @@ public function setUp(): void { parent::setUp(); - $this->category = CategoryFactory::new()->create(); + $this->category = Category::factory()->create(); } /** @test */ public function it_belongs_to_products() { - $product = ProductFactory::new()->create(); + $product = Product::factory()->create(); $this->category->products()->attach($product); @@ -34,7 +34,7 @@ public function it_belongs_to_products() /** @test */ public function it_has_media() { - $media = MediumFactory::new()->create(); + $media = Medium::factory()->create(); $this->category->media()->attach($media); diff --git a/tests/Unit/DiscountRepositoryTest.php b/tests/Unit/DiscountRepositoryTest.php index d96710a4..18f0c2c6 100644 --- a/tests/Unit/DiscountRepositoryTest.php +++ b/tests/Unit/DiscountRepositoryTest.php @@ -4,8 +4,8 @@ use Bazar\Contracts\Discount as Contract; use Bazar\Contracts\Discountable; -use Bazar\Database\Factories\CartFactory; -use Bazar\Database\Factories\ProductFactory; +use Bazar\Models\Cart; +use Bazar\Models\Product; use Bazar\Support\Facades\Discount; use Bazar\Tests\TestCase; @@ -17,11 +17,11 @@ public function setUp(): void { parent::setUp(); - $products = ProductFactory::new()->count(2)->create()->mapWithKeys(function ($product) { + $products = Product::factory()->count(2)->create()->mapWithKeys(function ($product) { return [$product->id => ['price' => $product->price, 'quantity' => 1]]; })->toArray(); - $this->cart = CartFactory::new()->create(); + $this->cart = Cart::factory()->create(); $this->cart->products()->attach($products); Discount::register('custom-30', 30); diff --git a/tests/Unit/ImageTest.php b/tests/Unit/ImageTest.php index c1eabb1b..f5e3a508 100644 --- a/tests/Unit/ImageTest.php +++ b/tests/Unit/ImageTest.php @@ -3,7 +3,7 @@ namespace Bazar\Tests\Unit; use Bazar\Conversion\Image; -use Bazar\Database\Factories\MediumFactory; +use Bazar\Models\Medium; use Bazar\Tests\TestCase; use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Storage; @@ -20,7 +20,7 @@ public function setUp(): void /** @test */ public function jpeg_can_be_converted() { - $medium = MediumFactory::new()->create(['file_name' => 'test.jpg']); + $medium = Medium::factory()->create(['file_name' => 'test.jpg']); Storage::disk('public')->makeDirectory($medium->id); @@ -56,7 +56,7 @@ public function jpeg_can_be_converted() /** @test */ public function png_can_be_converted() { - $medium = MediumFactory::new()->create(['file_name' => 'test.png']); + $medium = Medium::factory()->create(['file_name' => 'test.png']); Storage::disk('public')->makeDirectory($medium->id); @@ -94,7 +94,7 @@ public function png_can_be_converted() /** @test */ public function gif_can_be_converted() { - $medium = MediumFactory::new()->create(['file_name' => 'test.png']); + $medium = Medium::factory()->create(['file_name' => 'test.png']); Storage::disk('public')->makeDirectory($medium->id); @@ -130,7 +130,7 @@ public function gif_can_be_converted() /** @test */ public function webp_can_be_converted() { - $medium = MediumFactory::new()->create(['file_name' => 'test.png']); + $medium = Medium::factory()->create(['file_name' => 'test.png']); Storage::disk('public')->makeDirectory($medium->id); @@ -166,7 +166,7 @@ public function webp_can_be_converted() /** @test */ public function not_supported_types_cannot_be_converted() { - $medium = MediumFactory::new()->create(['file_name' => 'test.png']); + $medium = Medium::factory()->create(['file_name' => 'test.png']); Storage::disk('public')->makeDirectory($medium->id); diff --git a/tests/Unit/ItemTest.php b/tests/Unit/ItemTest.php index 6cd77e2d..f688dc39 100644 --- a/tests/Unit/ItemTest.php +++ b/tests/Unit/ItemTest.php @@ -4,8 +4,8 @@ use Bazar\Contracts\Stockable; use Bazar\Contracts\Taxable; -use Bazar\Database\Factories\ProductFactory; use Bazar\Models\Item; +use Bazar\Models\Product; use Bazar\Support\Facades\Cart; use Bazar\Support\Facades\Tax; use Bazar\Tests\TestCase; @@ -27,7 +27,7 @@ public function setUp(): void return $item->price * 0.1; }); - $product = ProductFactory::new()->create(); + $product = Product::factory()->create(); $this->item = Cart::add($product, 3, ['text' => 'test-text']); } diff --git a/tests/Unit/JobTest.php b/tests/Unit/JobTest.php index a1a22981..a915c6dc 100644 --- a/tests/Unit/JobTest.php +++ b/tests/Unit/JobTest.php @@ -2,7 +2,6 @@ namespace Bazar\Tests\Unit; -use Bazar\Database\Factories\MediumFactory; use Bazar\Jobs\MoveFile; use Bazar\Jobs\PerformConversions; use Bazar\Models\Medium; @@ -33,7 +32,7 @@ public function a_job_can_move_files() /** @test */ public function a_job_can_perform_conversions() { - $medium = MediumFactory::new()->create(); + $medium = Medium::factory()->create(); Storage::disk('public')->put( $medium->path(), UploadedFile::fake()->image('test.png')->get() ); diff --git a/tests/Unit/MediumTest.php b/tests/Unit/MediumTest.php index 9f1b1a1a..1ebd358e 100644 --- a/tests/Unit/MediumTest.php +++ b/tests/Unit/MediumTest.php @@ -2,7 +2,7 @@ namespace Bazar\Tests\Unit; -use Bazar\Database\Factories\MediumFactory; +use Bazar\Models\Medium; use Bazar\Support\Facades\Conversion; use Bazar\Tests\TestCase; use Illuminate\Support\Facades\Storage; @@ -15,7 +15,7 @@ public function setUp(): void { parent::setUp(); - $this->medium = MediumFactory::new()->create(); + $this->medium = Medium::factory()->create(); $this->app['config']->set('filesystems.disks.fake', [ 'driver' => 'local', diff --git a/tests/Unit/NotificationTest.php b/tests/Unit/NotificationTest.php index 72f89147..e2fa637d 100644 --- a/tests/Unit/NotificationTest.php +++ b/tests/Unit/NotificationTest.php @@ -2,7 +2,7 @@ namespace Bazar\Tests\Unit; -use Bazar\Database\Factories\OrderFactory; +use Bazar\Models\Order; use Bazar\Notifications\AdminNewOrder; use Bazar\Notifications\CustomerNewOrder; use Bazar\Tests\TestCase; @@ -14,7 +14,7 @@ class NotificationTest extends TestCase /** @test */ public function admin_order_notification_can_be_sent_on_different_channels() { - $order = OrderFactory::new()->create(); + $order = Order::factory()->create(); $notification = new AdminNewOrder($order); $this->assertInstanceOf(MailMessage::class, $notification->toMail($this->admin)); @@ -27,7 +27,7 @@ public function admin_order_notification_can_be_sent_on_different_channels() /** @test */ public function customer_order_notification_can_be_sent_on_different_channels() { - $order = OrderFactory::new()->create(); + $order = Order::factory()->create(); $notification = new CustomerNewOrder($order); $this->assertInstanceOf(MailMessage::class, $notification->toMail($this->user)); diff --git a/tests/Unit/OrderTest.php b/tests/Unit/OrderTest.php index 64a1d1d5..5642500f 100644 --- a/tests/Unit/OrderTest.php +++ b/tests/Unit/OrderTest.php @@ -3,10 +3,10 @@ namespace Bazar\Tests\Unit; use Bazar\Contracts\Breadcrumbable; -use Bazar\Database\Factories\AddressFactory; -use Bazar\Database\Factories\OrderFactory; -use Bazar\Database\Factories\ProductFactory; -use Bazar\Database\Factories\TransactionFactory; +use Bazar\Models\Address; +use Bazar\Models\Order; +use Bazar\Models\Product; +use Bazar\Models\Transaction; use Bazar\Tests\TestCase; class OrderTest extends TestCase @@ -17,9 +17,9 @@ public function setUp(): void { parent::setUp(); - $this->order = OrderFactory::new()->create(); + $this->order = Order::factory()->create(); - $this->products = ProductFactory::new()->count(3)->create()->mapWithKeys(function ($product) { + $this->products = Product::factory()->count(3)->create()->mapWithKeys(function ($product) { return [$product->id => ['quantity' => mt_rand(1, 5), 'tax' => 0, 'price' => $product->price]]; }); @@ -42,7 +42,7 @@ public function it_can_belong_to_a_customer() public function it_has_transactions() { $transactions = $this->order->transactions()->saveMany( - TransactionFactory::new()->count(3)->make() + Transaction::factory()->count(3)->make() ); $this->assertSame( @@ -54,7 +54,7 @@ public function it_has_transactions() public function it_has_address() { $address = $this->order->address()->save( - AddressFactory::new()->make() + Address::factory()->make() ); $this->assertSame($address->id, $this->order->address->id); @@ -63,7 +63,7 @@ public function it_has_address() /** @test */ public function it_has_products() { - $product = ProductFactory::new()->create(); + $product = Product::factory()->create(); $this->order->products()->attach($product, ['price' => 100, 'tax' => 0, 'quantity' => 3]); diff --git a/tests/Unit/ProductTest.php b/tests/Unit/ProductTest.php index a18c64b1..8b4d09ca 100644 --- a/tests/Unit/ProductTest.php +++ b/tests/Unit/ProductTest.php @@ -5,12 +5,12 @@ use Bazar\Casts\Inventory; use Bazar\Casts\Prices; use Bazar\Contracts\Breadcrumbable; -use Bazar\Database\Factories\CartFactory; -use Bazar\Database\Factories\CategoryFactory; -use Bazar\Database\Factories\MediumFactory; -use Bazar\Database\Factories\OrderFactory; -use Bazar\Database\Factories\ProductFactory; -use Bazar\Database\Factories\VariantFactory; +use Bazar\Models\Cart; +use Bazar\Models\Category; +use Bazar\Models\Medium; +use Bazar\Models\Order; +use Bazar\Models\Product; +use Bazar\Models\Variant; use Bazar\Tests\TestCase; use Illuminate\Support\Str; @@ -22,7 +22,7 @@ public function setUp(): void { parent::setUp(); - $this->product = ProductFactory::new()->create([ + $this->product = Product::factory()->create([ 'properties' => [ 'Size' => ['XS', 'S', 'M', 'L'], 'Material' => ['Gold', 'Silver'], @@ -33,7 +33,7 @@ public function setUp(): void /** @test */ public function it_belongs_to_orders() { - $order = OrderFactory::new()->create(); + $order = Order::factory()->create(); $this->product->orders()->attach($order, ['price' => 100, 'tax' => 0, 'quantity' => 3]); @@ -45,7 +45,7 @@ public function it_belongs_to_orders() /** @test */ public function it_belongs_to_carts() { - $cart = CartFactory::new()->create(); + $cart = Cart::factory()->create(); $this->product->carts()->attach($cart, ['price' => 100, 'tax' => 0, 'quantity' => 3]); @@ -57,7 +57,7 @@ public function it_belongs_to_carts() /** @test */ public function it_belongs_to_categories() { - $category = CategoryFactory::new()->create(); + $category = Category::factory()->create(); $this->product->categories()->attach($category); @@ -69,7 +69,7 @@ public function it_belongs_to_categories() /** @test */ public function it_has_media() { - $medium = MediumFactory::new()->create(); + $medium = Medium::factory()->create(); $this->product->media()->attach($medium); @@ -80,7 +80,7 @@ public function it_has_media() public function it_has_variants() { $variant = $this->product->variants()->save( - VariantFactory::new()->make([ + Variant::factory()->make([ 'variation' => ['Height' => 100, 'Width' => 100], ]) ); diff --git a/tests/Unit/ShippingTest.php b/tests/Unit/ShippingTest.php index 40bd2fcc..c6a7ed26 100644 --- a/tests/Unit/ShippingTest.php +++ b/tests/Unit/ShippingTest.php @@ -3,10 +3,7 @@ namespace Bazar\Tests\Unit; use Bazar\Contracts\Taxable; -use Bazar\Database\Factories\AddressFactory; -use Bazar\Database\Factories\CartFactory; -use Bazar\Database\Factories\OrderFactory; -use Bazar\Database\Factories\ShippingFactory; +use Bazar\Models\Address; use Bazar\Models\Cart; use Bazar\Models\Order; use Bazar\Models\Shipping; @@ -27,8 +24,8 @@ public function setUp(): void return $item->price * 0.1; }); - $this->cart = CartFactory::new()->create(); - $this->shipping = ShippingFactory::new()->make(); + $this->cart = Cart::factory()->create(); + $this->shipping = Shipping::factory()->make(); $this->shipping->shippable()->associate($this->cart)->save(); } @@ -44,8 +41,8 @@ public function a_shipping_belongs_to_a_cart() /** @test */ public function a_shipping_belongs_to_an_order() { - $order = $this->admin->orders()->save(OrderFactory::new()->make()); - $shipping = ShippingFactory::new()->make(); + $order = $this->admin->orders()->save(Order::factory()->make()); + $shipping = Shipping::factory()->make(); $shipping->shippable()->associate($order)->save(); $this->assertSame( @@ -57,12 +54,12 @@ public function a_shipping_belongs_to_an_order() /** @test */ public function a_shipping_has_address() { - $order = $this->admin->orders()->save(OrderFactory::new()->make()); - $shipping = ShippingFactory::new()->make(); + $order = $this->admin->orders()->save(Order::factory()->make()); + $shipping = Shipping::factory()->make(); $shipping->shippable()->associate($order)->save(); $address = $shipping->address()->save( - AddressFactory::new()->make() + Address::factory()->make() ); $this->assertSame($address->id, $shipping->address->id); diff --git a/tests/Unit/TaxRepositoryTest.php b/tests/Unit/TaxRepositoryTest.php index ae494814..159580e0 100644 --- a/tests/Unit/TaxRepositoryTest.php +++ b/tests/Unit/TaxRepositoryTest.php @@ -4,8 +4,8 @@ use Bazar\Contracts\Tax as Contract; use Bazar\Contracts\Taxable; -use Bazar\Database\Factories\CartFactory; -use Bazar\Database\Factories\ProductFactory; +use Bazar\Models\Cart; +use Bazar\Models\Product; use Bazar\Models\Shipping; use Bazar\Support\Facades\Tax; use Bazar\Tests\TestCase; @@ -18,11 +18,11 @@ public function setUp(): void { parent::setUp(); - $products = ProductFactory::new()->count(2)->create()->mapWithKeys(function ($product) { + $products = Product::factory()->count(2)->create()->mapWithKeys(function ($product) { return [$product->id => ['price' => $product->price, 'tax' => 0, 'quantity' => 1]]; })->toArray(); - $this->cart = CartFactory::new()->create(); + $this->cart = Cart::factory()->create(); $this->cart->products()->attach($products); Tax::register('custom-30', 30); diff --git a/tests/Unit/TransactionTest.php b/tests/Unit/TransactionTest.php index d3753627..07e6f864 100644 --- a/tests/Unit/TransactionTest.php +++ b/tests/Unit/TransactionTest.php @@ -2,8 +2,8 @@ namespace Bazar\Tests\Unit; -use Bazar\Database\Factories\OrderFactory; -use Bazar\Database\Factories\TransactionFactory; +use Bazar\Models\Order; +use Bazar\Models\Transaction; use Bazar\Support\Facades\Gateway; use Bazar\Tests\TestCase; @@ -15,8 +15,8 @@ public function setUp(): void { parent::setUp(); - $this->order = $this->admin->orders()->save(OrderFactory::new()->make()); - $this->transaction = TransactionFactory::new()->make(); + $this->order = $this->admin->orders()->save(Order::factory()->make()); + $this->transaction = Transaction::factory()->make(); $this->transaction->order()->associate($this->order)->save(); } diff --git a/tests/Unit/UserTest.php b/tests/Unit/UserTest.php index a66e034c..a8607ba7 100644 --- a/tests/Unit/UserTest.php +++ b/tests/Unit/UserTest.php @@ -3,9 +3,9 @@ namespace Bazar\Tests\Unit; use Bazar\Contracts\Breadcrumbable; -use Bazar\Database\Factories\AddressFactory; -use Bazar\Database\Factories\CartFactory; -use Bazar\Database\Factories\OrderFactory; +use Bazar\Models\Address; +use Bazar\Models\Cart; +use Bazar\Models\Order; use Bazar\Tests\TestCase; class UserTest extends TestCase @@ -16,7 +16,7 @@ public function it_can_have_a_cart() $this->assertNull($this->user->cart); $cart = $this->user->cart()->save( - CartFactory::new()->make() + Cart::factory()->make() ); $this->user->refresh(); @@ -28,7 +28,7 @@ public function it_can_have_a_cart() public function it_has_orders() { $orders = $this->user->orders()->saveMany( - OrderFactory::new()->count(3)->make() + Order::factory()->count(3)->make() ); $this->assertSame( @@ -40,7 +40,7 @@ public function it_has_orders() public function it_has_addresses() { $addresses = $this->user->addresses()->saveMany( - AddressFactory::new()->count(3)->make() + Address::factory()->count(3)->make() ); $this->assertSame($this->user->addresses->pluck('id')->all(), $addresses->pluck('id')->all()); diff --git a/tests/Unit/ValidationTest.php b/tests/Unit/ValidationTest.php index f05e17d4..51609c29 100644 --- a/tests/Unit/ValidationTest.php +++ b/tests/Unit/ValidationTest.php @@ -2,9 +2,9 @@ namespace Bazar\Tests\Unit; -use Bazar\Database\Factories\OrderFactory; -use Bazar\Database\Factories\ProductFactory; -use Bazar\Database\Factories\VariantFactory; +use Bazar\Models\Order; +use Bazar\Models\Product; +use Bazar\Models\Variant; use Bazar\Rules\Option; use Bazar\Rules\TransactionAmount; use Bazar\Rules\Vat; @@ -35,7 +35,7 @@ public function it_validatates_vat_numbers() /** @test */ public function it_validates_transaction_amounts() { - $order = OrderFactory::new()->create(); + $order = Order::factory()->create(); $v = new Validator($this->translator, ['amount' => 0], ['amount' => [new TransactionAmount($order)]]); $this->assertTrue($v->passes()); @@ -47,9 +47,9 @@ public function it_validates_transaction_amounts() /** @test */ public function it_validates_variant_options() { - $product = ProductFactory::new()->create(); + $product = Product::factory()->create(); $variant = $product->variants()->save( - VariantFactory::new()->make() + Variant::factory()->make() ); $v = new Validator( diff --git a/tests/Unit/VariantTest.php b/tests/Unit/VariantTest.php index 03dc403d..24e1019e 100644 --- a/tests/Unit/VariantTest.php +++ b/tests/Unit/VariantTest.php @@ -3,8 +3,8 @@ namespace Bazar\Tests\Unit; use Bazar\Contracts\Breadcrumbable; -use Bazar\Database\Factories\ProductFactory; -use Bazar\Database\Factories\VariantFactory; +use Bazar\Models\Product; +use Bazar\Models\Variant; use Bazar\Tests\TestCase; class VariantTest extends TestCase @@ -15,9 +15,9 @@ public function setUp(): void { parent::setUp(); - $this->product = ProductFactory::new()->create(); + $this->product = Product::factory()->create(); - $this->variant = VariantFactory::new()->make(); + $this->variant = Variant::factory()->make(); $this->variant->product()->associate($this->product); $this->variant->save(); } @@ -31,7 +31,7 @@ public function it_belongs_to_a_product() /** @test */ public function it_has_alias_attribute() { - $variant = VariantFactory::new()->make(['alias' => 'Fake']); + $variant = Variant::factory()->make(['alias' => 'Fake']); $this->assertSame('Fake', $variant->alias);