Hello everyone, I need help on bellow issue.
I have feature testing like this
<?php
namespace Tests\Feature;
use Tests\TestCase;
use Illuminate\Support\Arr;
use Database\Seeders\ShipperSeeder;
use Database\Seeders\CategorySeeder;
use Database\Seeders\ShipperTypeSeeder;
use Database\Seeders\PaymentMethodSeeder;
use Database\Seeders\ProductSeeder;
use Database\Seeders\VariantSeeder;
use Illuminate\Support\Facades\DB;
class OrderTest extends TestCase
{
public function prepare(): void
{
DB::table('categories')->truncate();
$this->seed([
CategorySeeder::class,
ProductSeeder::class,
VariantSeeder::class,
ShipperTypeSeeder::class,
ShipperSeeder::class,
PaymentMethodSeeder::class
]);
}
public function orderRequest(): array
{
$order = [
'voucher_id' => null,
'shipper_id' => 1,
'amount' => 40000,
'discount' => 0,
'point' => 200,
'payment_type' => 'saldo',
'bank' => null,
'shipment_weight' => 1,
'shipment_weight_unit' => 'kg',
'shipment_price' => 18000,
'shipment_eta' => '2-3 days',
'order_items' => [
[
'product_id' => 1,
'variant_id' => 1,
'qty' => 4,
'note' => null
]
]
];
return $order;
}
public function test_order_process_using_saldo_with_valid_request(): void
{
$this->prepare();
$this->register();
$userAddress = $this->storeAddress();
$orderRequest = array_merge(['user_address_id' => $userAddress['id']], $this->orderRequest());
$order = array_merge(['user_id' => $userAddress['user_id']], Arr::except($orderRequest, 'order_items'));
$response = $this->json('post', route('order.store'), $orderRequest);
$response->assertCreated();
$response->assertJson([
'rc' => config('rc.successfully.rc'),
'message' => config('rc.successfully.message'),
'data' => [
'order' => $order
]
]);
$this->assertDatabaseHas('orders', $order);
$this->assertAuthenticated();
}
public function test_order_process_using_bank_transfer_with_valid_request(): void
{
$this->prepare();
$this->register();
$userAddress = $this->storeAddress();
$orderRequest = array_merge([
'user_address_id' => $userAddress['id'],
'payment_type' => 'bank_transfer',
'bank' => 'bca',
], $this->orderRequest());
$order = array_merge(['user_id' => $userAddress['user_id']], Arr::except($orderRequest, 'order_items'));
$response = $this->json('post', route('order.store'), $orderRequest);
$response->assertCreated();
$response->assertJson([
'rc' => config('rc.successfully.rc'),
'message' => config('rc.successfully.message'),
'data' => [
'order' => $order
]
]);
$this->assertDatabaseHas('orders', $order);
$this->assertAuthenticated();
}
public function test_order_process_with_invalid_request(): void
{
$this->register();
$response = $this->json('post', route('order.store'));
$response->assertStatus(400);
$response->assertJson(config('rc.invalid_data'));
$response->assertInvalid(
['user_address_id', 'shipper_id', 'payment_type', 'shipment_weight', 'shipment_weight_unit', 'shipment_price', 'shipment_eta'],
'default',
'error'
);
$this->assertAuthenticated();
}
public function test_order_process_using_saldo_with_insufficient_balance(): void
{
$this->prepare();
$this->register();
$userAddress = $this->storeAddress();
$orderRequest = array_merge($this->orderRequest(), [
'user_address_id' => $userAddress['id'],
'amount' => 999999
]);
$order = array_merge(['user_id' => $userAddress['user_id']], Arr::except($orderRequest, 'order_items'));
$response = $this->json('post', route('order.store'), $orderRequest);
$response->assertStatus(400);
$response->assertJson(config('rc.insufficient_balance'));
$this->assertDatabaseMissing('orders', $order);
$this->assertAuthenticated();
}
public function test_order_process_with_product_out_of_stock(): void
{
$this->prepare();
$this->register();
$userAddress = $this->storeAddress();
$orderRequest = array_merge($this->orderRequest(), [
'user_address_id' => $userAddress['id'],
'order_items' => [
0 => [
'product_id' => 1,
'variant_id' => 1,
'qty' => 1000,
'note' => null
]
]
]);
$order = array_merge(['user_id' => $userAddress['user_id']], Arr::except($orderRequest, 'order_items'));
$response = $this->json('post', route('order.store'), $orderRequest);
$response->assertStatus(400);
$response->assertJson(config('rc.out_of_stock'));
$this->assertDatabaseMissing('orders', $order);
$this->assertAuthenticated();
}
public function test_order_process_without_authentication(): void
{
$response = $this->json('post', route('order.store'));
$response->assertUnauthorized();
$response->assertJson(config('rc.unauthenticated'));
$this->assertGuest();
}
}
When I am running test one by one of function in testing using extension better php unit, the result is passed. But, when I am running testing one class, the testing not ended and not showing error in long time. How to fix it?