benou101's avatar

Integration Test: use URL::route or hardcode the route

When testing a controller, all the example I've seen so far hardcode the route. For example, to test if you can delete something, I see: $this->delete(''something/'.$something->id).

But if the path to "something" becomes "somethingElse", you have to change all your tests. Would it be better to do: $this->delete(URL::route('something.destroy', $something->id)) This way, the only thing you have to change is web.php if the path changes.

What are the pros and cons ?

0 likes
2 replies
fylzero's avatar

@benou101 It should be fine either way. If you see value in using the named route helper, then just use that. Just make sure your tests fail if you change the route and you should be covered.

25 likes
Sti3bas's avatar

@benou101 I'm always using named routes with route helper, so that I could change the path in my routes file without having to update the tests and I never had any issues with it.

1 like

Please or to participate in this conversation.