繁体   English   中英

如何在Laravel 5.5中正确编写控制器方法的单元测试?

[英]How to correctly write a unit test for controllers methods in Laravel 5.5?

请检查我在控制器中使用的代码:

class ObjectsPagesController extends Controller
{
    public function destroy(Destroy $destroy, $id)
    {
        $objectsPage = ObjectsPages::with( 'ObjectsPagesRelation')->where('group_id', $id)->first();
        if (isset($objectsPage)) {

            $objectsPage->delete();
            $objectsPage->ObjectsPagesRelation()->delete();
            return redirect()->route('objects.pages.index')->with('success', 'done');  

        }else{
            abort(404);
        }
    }
}

在我的请求页面上,我写了以下代码:

class Destroy extends FormRequest
{
    public function authorize()
    {
        return Auth::user()->can('del_objects_pages');
    }
    public function rules()
    {
        return [
            //
        ];
    }
}

我尝试下面的工匠命令

php artisan make:test Pages --unit`

但是laravel 5.5无法找到明确的指示下一步做什么?

<?php 
  class StoreObjectPageTest extends TestCase
{
    public function testStoreObjectIsCreated()
    {
        $this->actingAs($someUser)->post('/some/url');

        $this->assertDatabaseHas('store_objects', [
            // The attributes of a row you're expecting to see in DB
        ]);
    }
}
?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM