Order Item Tests
Automated tests provide stability which allows you to play around with new ideas and tools.
We'll cover the following...
Setup
We will need a few components for each of our tests: a logged-in user, a restaurant, a menu item, a table, etc. PHPUnit’s setup()
method can be helpful for this.
Press + to interact
<?phpnamespace Tests\Feature;use App\Models\MenuItem;use App\Models\Order;use App\Models\Restaurant;use App\Models\Table;use App\Models\User;use Illuminate\Foundation\Testing\RefreshDatabase;use Illuminate\Testing\Fluent\AssertableJson;use Laravel\Sanctum\Sanctum;use Tests\TestCase;final class OrderItemTest extends TestCase{use RefreshDatabase;private $user;private $restaurant;private $table;private $menuItem;private $order;protected function setUp(): void{parent::setUp();$this->user = User::factory()->create();$this->restaurant = Restaurant::factory()->create(['user_id' => $this->user->id,]);$this->menuItem = MenuItem::factory()->create(['restaurant_id' => $this->restaurant->id,]);$this->table = Table::factory()->create(['restaurant_id' => $this->restaurant->id,]);$this->order = Order::factory()->create(['restaurant_id' => $this->restaurant->id,'table_id' => $this->table->id,]);Sanctum::actingAs($this->user, ['*']);}}