mardi 17 septembre 2019

How run delete method in TDD tests?

In laravel 5.8 app I make TDD tests for admin CRUD operations for table , make post, put requests, but I failed to make delete :

    public function testVoteCategoriesCrud()
    {

        $this->withoutExceptionHandling();
        $this->withoutMiddleware();

        $newVoteCategoryRow         = factory('App\VoteCategory')->make(); // Create new VoteCategory Data Row
        $newVoteCategoryRow->name   .= ' created on ' . strftime("%Y-%m-%d %H:%M:%S:%U") ;
        $new_vote_category_row_name = $newVoteCategoryRow->name;

        $response = $this->actingAs($loggedUser)->post('/admin/vote-categories', $newVoteCategoryRow->toArray());
        $this->assertCount( $original_vote_categories_count+1, VoteCategory::all() );    // to use HTTP_RESPONSE_OK
        $response->assertRedirect('/admin/vote-categories'); // after successful post request redirect to '/admin/vote-categories'

        ...
        $response = $this->actingAs($loggedUser)->delete( '/admin/vote-categories', ['id'=>$checkCreatedVoteCategory->id] );

        $this->assertCount( $original_vote_categories_count, VoteCategory::all() );    // to use HTTP_RESPONSE_OK
        $response->assertRedirect('/admin/vote-categories'); // after successful put request redirect to '/admin/vote-categories'

But I got error 
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException: The DELETE method is not supported for this route. Supported methods: GET, HEAD, POST.

on delete method above.

How correctly delete row in tests?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire