简单的php单元测试,但有点卡住了

简单的php单元测试,但有点卡住了,php,unit-testing,phpunit,Php,Unit Testing,Phpunit,我几天前开始为我的函数做一些单元测试,但我真的找不到如何正确地为这个函数做测试。我认为这很容易,但我还缺少一些东西 /** * Tests model->function() */ public function testFunction() { // TODO Auto-generated model->testFunction() $this->markTestIncomplete ( "function test not implemented

我几天前开始为我的函数做一些单元测试,但我真的找不到如何正确地为这个函数做测试。我认为这很容易,但我还缺少一些东西

    /**
 * Tests model->function()
 */
public function testFunction() {
    // TODO Auto-generated model->testFunction()
    $this->markTestIncomplete ( "function test not implemented" );
    $this->model->testFunction('', '5');
    $this->model->testFunction('test', '');
    $this->model->testFunction('test', 'a');
    $this->model->testFunction('1', '5');

}
这就是我所拥有的,我不能忽视这些测试。 我想要的是测试我的函数(它需要两个参数,都是整数)并检查:

  • 这两个参数都不是空的吗
  • 这两个参数都是整数类型的吗
有人能帮我吗

非常感谢

第一句话

$this->markTestIncomplete ()
将导致PHPUnit传递此测试文件,并在输出中将其标记为未完成(已执行)

其次,测试的格式不正确。您需要创建对象,然后测试它

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

public function testFunction()
{
    $this->assertEquals('test', $this->model->Function(5));  // Test what the function should return, using parameters replacing the 5
}
函数应该根据我在尝试中看到的内容接受一个参数。然后这个函数将返回一些您可以根据其进行计算的内容

或者,您可以使用数据提供程序为测试提供多个值并查看输出。有关更多信息,请参阅PHPUnit手册