Php Laravel测试未运行

Php Laravel测试未运行,php,laravel,phpunit,Php,Laravel,Phpunit,我已经测试了我的ADS控制器。 当我运行$phpunit时,会收到以下消息: 时间:208毫秒,内存:16.50Mb正常(3次测试,4次断言) 然后我移动到文件夹reports/covarage,打开文件AdsController.php.html。 并看到方法getNew()尚未启动。怎么会?仅运行方法index()。为什么? public function setUp() { parent::setUp(); $this->mock = $

我已经测试了我的ADS控制器。 当我运行
$phpunit
时,会收到以下消息:

时间:208毫秒,内存:16.50Mb正常(3次测试,4次断言)

然后我移动到文件夹
reports/covarage
,打开文件
AdsController.php.html
。 并看到方法
getNew()
尚未启动。怎么会?仅运行方法
index()
。为什么?

  public function setUp()
    {
        parent::setUp();

        $this->mock = $this->mock('App\Models\Advertisement');

        $this->builder = $this->mock('Illuminate\Database\Eloquent\Builder');
    }

  public function testIndex()
    {
        $this->mock
            ->shouldReceive('approved')
            ->atLeast()->once()->andReturn($this->builder);

        $this->builder->shouldReceive('with')->times(4)->andReturn($this->builder);

        $this->builder->shouldReceive('orderBy')->once()->andReturn($this->builder);

        $this->builder->shouldReceive('paginate')->once()->andReturn($this->builder);


        $this->call('GET', 'ads');

        $this->assertResponseOk();
        $this->assertViewHas('ads');
    }

    /**
     * @return void
     */
    public function testGetNew()
    {
        $this->mock
                ->shouldReceive('approved')
                ->atLeast()->once()->andReturn($this->builder);

        $this->builder->shouldReceive('with')->times(4)->andReturn($this->builder);


        $this->builder->shouldReceive('where')->once()->andReturn($this->builder);
        $this->builder->shouldReceive('orderBy')->once()->andReturn($this->builder);
        $this->builder->shouldReceive('get')->once()->andReturn($this->builder);
        $this->call('GET', 'getNewAds');
        $this->assertResponseOk();


    }
以及我在AdsController上的方法:

public function index(Request $request, Advertisement $advertisement)
{
    $ads = $advertisement::approved()
            ->with('city')
            ->with('ads_attachment')
            ->with('category')
            ->with('user')->orderBy('id', 'desc')->paginate(9);

    return view('ads.index', ['ads' => $ads]);
    //
}
 public function getNew(Advertisement $advertisement)
    {
        $ads = $advertisement::approved()
            ->with('city')
            ->with('ads_attachment')
            ->with('category')
            ->with('user')->where('id', '>', Input::get('last_id'))->orderBy('id', 'desc')->get();
        return \Response::json(['ads' => $ads]);
    }
路线:

Route::resource('ads', 'AdsController');//->
$router->get('/getNewAds', 'AdsController@getNew');
路由器在浏览器中工作

UDP


我删除了
testIndex()
方法并运行了测试。报告查看并发现方法
index()
仍在运行。我的记录没有被覆盖?怎么会?访问权限有

请在问题中添加相关路线好吗?@lukasgeiter我添加了路线