2014-10-30 109 views
0

我是新来使用phpunit。我在Netbeans 8.0.1上运行测试。该代码是https://phpunit.de/manual/4.3/en/writing-tests-for-phpunit.html页面上的Example 2.2。我收到一条错误消息:“StackTest :: testPop() 传递给StackTest :: testPop()的参数1必须是一个数组,给定为null。” 我不知道为什么有错误。我是否需要输入其他代码或其他内容? 感谢您的回复,提前。phpunit依赖关系netbean 8.0.1的StackTest

以下是代码:

类StackTest PHPUnit_Framework_TestCase的扩展{

public function testEmpty() { 
    $stack = array(); 
    $this->assertEmpty($stack); 

    return $stack; 
} 

/** 
* @depends testEmpty 
*/ 
public function testPush(array $stack) { 
    array_push($stack, 'foo'); 
    $this->assertEquals('foo', $stack[count($stack)-1]); 
    $this->assertNotEmpty($stack); 
} 

/** 
* @depends testPush 
*/ 
public function testPop(array $stack) { 
    $this->assertEquals('foo', array_pop($stack)); 
    $this->assertEmpty($stack); 
} 

}

回答

0

我犯了一个错误。原始来源没有错误。

/** 
* @depends testEmpty 
*/ 
public function testPush(array $stack) { 
    array_push($stack, 'foo'); 
    $this->assertEquals('foo', $stack[count($stack)-1]); 
    $this->assertNotEmpty($stack); 

    return $stack; // I omitted this line; 
}