You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
given a named route admin.work.show with the following pattern: /works/{work}
and given the following simple test:
publicfunctionmanagers_can_create_works()
{
$this->createManager();
$this->loginManager();
$workRawAttributes = Work::factory()->raw();
// create a new work$response = $this->from(route('admin.work.create'))
->post(route('admin.work.store'), $workRawAttributes);
// assert that the the db has this work$this->assertDatabaseHas('works', $workRawAttributes);
// and assert that we are redirected to the work view page$response->assertRedirect(route('admin.work.show', [missing parameter]));
}
my test fails in the second assert because I am missing the required {work} parameter from my url.
How do I access either the slug or the model generated in my Work controller's store method?
a possible solution would be to generate the slug from the raw attributes in my test using Str::slug and use that instead for the final assertion but something feels off about it. I think it's because, in this scenario, I'm generating this slug with Laravel and comparing it to a slug generated by Sluggable which somehow feels nimble to me. I feel like this could produce unexpected results but please correct me if I am wrong or if I shouldn't be worrying about this, thanks ✌️
this works but feels... off?
publicfunctionmanagers_can_create_works()
{
$this->createManager();
$this->loginManager();
$workRawAttributes = Work::factory()->raw();
$slug = Str::slug($workRawAttributes['name']); // i don't like this// create a new work$response = $this->from(route('admin.work.create'))
->post(route('admin.work.store'), $workRawAttributes);
// assert that the the db has this work$this->assertDatabaseHas('works', $workRawAttributes);
// and assert that we are redirected to the work view page$response->assertRedirect(route('admin.work.show', $slug));
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
given a named route
admin.work.show
with the following pattern:/works/{work}
and given the following simple test:
my test fails in the second assert because I am missing the required
{work}
parameter from my url.How do I access either the slug or the model generated in my
Work
controller'sstore
method?a possible solution would be to generate the slug from the raw attributes in my test using
Str::slug
and use that instead for the final assertion but something feels off about it. I think it's because, in this scenario, I'm generating this slug with Laravel and comparing it to a slug generated by Sluggable which somehow feels nimble to me. I feel like this could produce unexpected results but please correct me if I am wrong or if I shouldn't be worrying about this, thanks ✌️this works but feels... off?
Beta Was this translation helpful? Give feedback.
All reactions