mercredi 18 juillet 2018

laravel phpunit testing expecting status code 201 but received 302?

I have a simple PostController with a store method that receives data, validates it, stores it and then redirects to /posts with a success message.

I have a written a test to ensure that the post is created and saved as follows:

/** test */
public function testStore()
{
    $user = factory('App\User')->create();

    $post = factory('App\Post')->create(['user_id' => $user->id]);

    $response = $this->actingAs($user)
                    ->json('POST', '/notice', $post->toArray())
                    ->assertStatus(201)
                    ->assertJson([
                        'created' => true,
                    ]);

}

But I am receiving 301(redirection) instead of 201. I do not understand this.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire