2014-11-22 35 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'); 
    } 

}