2014-11-22 106 views
0

我想测试其中一个类,但它看起来像Phpunit不起作用。

这是下面的测试:Laravel:PHPUnit测试不触发

<?php 

use NERO\Datagrids\Datagrid; 

class DatagridTest extends TestCase 
{ 

    public function __construct() 
    { 
     $this->datagrid = new Datagrid; 
    } 

    public function testStopMethod() 
    { 
     $response = $this->datagrid->stop(); 
     $this->assertEquals($response, 'Stop'); 
    } 

} 

和类本身:

<?php 

namespace NERO\Datagrids; 

class Datagrid { 

    public function stop() 
    { 
     return 'Stop'; 
    } 

} 

我没有得到事件在命令行中的任何效应初探。我做了以下事情,没有任何反应。

intelis:laravel me$ clear 
intelis:laravel me$ vendor/bin/phpunit 
intelis:laravel me$ 

感谢您的帮助!

回答

1

请不要使用__construct,而不是:

<?php 

use NERO\Datagrids\Datagrid; 

class DatagridTest extends TestCase 
{ 
    protected $datagrid; 

    public function setUp() 
    { 
     $this->datagrid = new Datagrid; 
    } 

    public function testStopMethod() 
    { 
     $response = $this->datagrid->stop(); 
     $this->assertEquals($response, 'Stop'); 
    } 

}