Answer the question
In order to leave comments, you need to log in
What is the reason for Laravel PHPUnit Future test in controller not accepting Entity variable when updating in route?
Good afternoon.
There is a test to update the service:
class ServiceTest extends TestCase
{
use WithFaker;
use DatabaseTransactions;
public function test_category_update_success(): void
{
$this->withoutMiddleware();
$this->signInAdmin();
$service = factory(Service::class)->create([
'parent_id' => function () {
return Service::find(2)->id;
}
]);
$putArr = [
'name' => $this->faker->name,
'parent_id' => Service::find(1)->id
];
$response = $this->put(route('admin.services.update', $service), $putArr);
throw $response->exception;
$this->assertDatabaseHas('services', $putArr);
$response
->assertStatus(302)
->assertRedirect(route('admin.services.show', $service))
->assertSessionHas('success', __('messages.success'));
}
protected function signInAdmin()
{
$user = factory(User::class, 'admin')->create();
$this->actingAs($user);
return $user;
}
}
class ServicesController extends Controller
{
public function update(ServiceRequest $request, Service $service)
{
throw new Exception(print_r([
'Controller',
'$service->id' => $service->id,
'$request->all' => $request->all()
]));
$service->name = $request['name'];
$service->save();
return redirect()->route('admin.services.show', $service)->with('success', __('messages.success'));
}
}
throw new Exception(print_r([
'$routeUpdate' => route('admin.services.update', $service),
'$routeShow' => route('admin.services.show', $service)
]));
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question