我是新手使用phpunit。我在Netbeans 8.0.1上运行测试。代码是https://phpunit.de/manual/4.3/en/writing-tests-for-phpunit.html页面上的示例2.2。我收到一条错误消息:“StackTest :: testPop() 传递给StackTest :: testPop()的参数1必须是一个数组,给定null。“ 我不知道为什么会出现错误。我是否需要输入其他代码或其他内容? 感谢您提前回复。
以下是代码:
类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 :(得分: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;
}