Laravel Unit使用身份验证测试呼叫路由

时间:2014-05-07 07:58:08

标签: php unit-testing laravel-4

我想在laravel 4.1中创建单元测试。我是laravel和PHP的新手。所以我想知道如何拨打下面提到的路线。

这是我使用身份验证过滤器的路线。

Route.php

Route::get('um',array('before' => 'auth.required'),'UMController@showAll');

该路线的控制器是

UMController.php

public function showAll(){

      $um=Um::all();
      return $um;
    }

调用路线的我的单位测试功能是。

UMTest.php

public function testPush()
    {
        $this->be(User::find(7));
        $this->call('GET', 'um');
    }

但是我得到了错误。 ErrorException:call_user_func_array()期望参数1是有效的回调,没有给定的数组或字符串

2 个答案:

答案 0 :(得分:0)

我认为你的路线是问题

Route::get('um',array('before' => 'auth.required'),'UMController@showAll');

试试这个

Route::get('um', array('before' => 'auth.required', 'uses' => 'UMController@showAll'));

答案 1 :(得分:0)

reference

我尝试很多次这个例子对我有用

Route::get(‘start’, array(‘before’ => ‘auth.required’ => ‘data@yourdomain’));