/**
* @test
* */
public function unauthenticated_users_may_not_add_reply(){
//$this->expectException('Illuminate\Auth\AuthenticationException');
$thread = factory('App\Thread')->create();
$reply = factory('App\Reply')->create();
$this->post($thread->path().'/replies', $reply->toArray());
}
Running php artisan test gives me a warning/error saying this test did not perform any assertions. I would assume it failed the test case, how do I make the test case pass without using assertion where it is not needed?
You could assert that you are redirect to /login, also, use make() instead of create() to the reply, and assert that database has no records in replies table
@nickywan123 yes, it's wrong, if you use create - it create a new record, and right to the next line you send a post request to create another one..you will end up with two replies in your database.
let's write a test to check if authenticated user can leave a reply with create
$this->actingAs(factory('App\User')->create());
$thread = factory('App\Thread')->create();
$reply = factory('App\Reply')->create(); // we already have a reply in a database
$this->post($thread->path().'/replies', $reply->toArray());
$this->assertDatabaseCount('replies', 1); // this explains why you need to use make
@nickywan123 Well, the idea of tests is that you actually test something. So you usually set something up, perform an action, and then perform assertions on the results. This is known as act–arrange–assert.