Tee*_*eps 5 php testing phpunit
我对我的 phpproject 有一些测试。我的测试:
class myTests extends PHPunit_Framework_Testcase{
public function testValidateInventoryNumber(){
include('includes/functions.php');
$con = connectToDatabase();
$resultTest1 = validateInventoryNumber("001234", $con);
$this->assertEquals("001234", $resultTest1['data']);
}
public function testValidateLabel(){
include('includes/functions.php');
$resultTest1 = validateLabel("Sample Label.");
$this->assertEquals("Sample Label.", $resultTest1['data']);
}
}
Run Code Online (Sandbox Code Playgroud)
函数validateInventoryNumber()和validateLabel()是在 中声明的includes/functions.php,所以我需要在两个测试中都包含这个文件,对吗?
如果我想运行测试文件,我会收到以下错误:
Fatal error: Cannot redeclare connectToDatabase() (previously declared in C:\xampp\htdocs\prototype\includes\functions.php:4) in C:\xampp\htdocs\prototype\includes\functions.php on line 10
Run Code Online (Sandbox Code Playgroud)
我认为这与测试开始时的包含有关,因为如果我注释掉其中一个测试,它就会正常工作。知道如何修复它吗?
感谢@Karlo Kokkak在评论中提到了解决方案。而不是include('includes/functions.php');使用include_once('includes/functions.php');.
| 归档时间: |
|
| 查看次数: |
2215 次 |
| 最近记录: |