count(3)->create(); $response = $this->get(route('compras.index')); $response->assertOk(); $response->assertJsonStructure([]); } #[Test] public function store_uses_form_request_validation(): void { $this->assertActionUsesFormRequest( \App\Http\Controllers\CompraController::class, 'store', \App\Http\Requests\CompraStoreRequest::class ); } #[Test] public function store_saves(): void { $fecha = Carbon::parse(fake()->dateTime()); $total = fake()->randomFloat(/** decimal_attributes **/); $estado = fake()->randomElement(/** enum_attributes **/); $response = $this->post(route('compras.store'), [ 'fecha' => $fecha->toDateTimeString(), 'total' => $total, 'estado' => $estado, ]); $compras = Compra::query() ->where('fecha', $fecha) ->where('total', $total) ->where('estado', $estado) ->get(); $this->assertCount(1, $compras); $compra = $compras->first(); $response->assertCreated(); $response->assertJsonStructure([]); } #[Test] public function show_behaves_as_expected(): void { $compra = Compra::factory()->create(); $response = $this->get(route('compras.show', $compra)); $response->assertOk(); $response->assertJsonStructure([]); } #[Test] public function update_uses_form_request_validation(): void { $this->assertActionUsesFormRequest( \App\Http\Controllers\CompraController::class, 'update', \App\Http\Requests\CompraUpdateRequest::class ); } #[Test] public function update_behaves_as_expected(): void { $compra = Compra::factory()->create(); $fecha = Carbon::parse(fake()->dateTime()); $total = fake()->randomFloat(/** decimal_attributes **/); $estado = fake()->randomElement(/** enum_attributes **/); $response = $this->put(route('compras.update', $compra), [ 'fecha' => $fecha->toDateTimeString(), 'total' => $total, 'estado' => $estado, ]); $compra->refresh(); $response->assertOk(); $response->assertJsonStructure([]); $this->assertEquals($fecha, $compra->fecha); $this->assertEquals($total, $compra->total); $this->assertEquals($estado, $compra->estado); } #[Test] public function destroy_deletes_and_responds_with(): void { $compra = Compra::factory()->create(); $response = $this->delete(route('compras.destroy', $compra)); $response->assertNoContent(); $this->assertModelMissing($compra); } }