Test failing: Proper way to test a POST submission
Controller:
public function create($channel, Request $request)
{
$thread = new Thread;
$thread->channel = $channel;
$thread->body = $request->body;
$thread->save();
$threads = Thread::latest()->where('channel', $channel)->get();
return view($channel, compact('threads'));
}
Test:
public function test_a_user_submit_a_thread()
{
$thread = factory('App\Thread')->make();
$this->post('/'.$thread->channel, $thread->toArray());
$this->get('/.'.$thread->channel)
->assertSee($thread->body);
}
The post works on the site when a user submits, however the test is failing
Error:
Failed asserting that
HTML>>>>>>>
contains "Aut provident libero nihil ab corporis distinctio. Repudiandae culpa consectetur at similique sed
beatae. Autem quasi velit rerum maxime commodi est animi.".
This request ($this->get('/.'.$thread->channel)->assertSee($thread->body);) is unnecessary since the post request already returns the view you want. Additionally, you have . in the URI for the GET request that probably is incorrect.