运行 如何在 TDD 测试中删除方法?
How run delete method in TDD tests?
在 laravel 5.8 应用程序中,我对 table 的管理员 CRUD 操作进行了 TDD 测试,发出 post,发出请求,但我未能进行删除 :
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.
关于上面的删除方法。
如何在测试中正确删除行?
我发现在routes/web中添加删除方法的决定。php:
Route::resource('vote-categories', 'Admin\VoteCategoriesController', ['except' => []])->middleware('WorkTextString');
Route::delete('vote-categories', 'Admin\VoteCategoriesController@destroy');
这对我有用
在 laravel 5.8 应用程序中,我对 table 的管理员 CRUD 操作进行了 TDD 测试,发出 post,发出请求,但我未能进行删除 :
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.
关于上面的删除方法。
如何在测试中正确删除行?
我发现在routes/web中添加删除方法的决定。php:
Route::resource('vote-categories', 'Admin\VoteCategoriesController', ['except' => []])->middleware('WorkTextString');
Route::delete('vote-categories', 'Admin\VoteCategoriesController@destroy');
这对我有用