&引用;致命错误:无法重新声明函数();在使用phpunit进行测试时发生

&引用;致命错误:无法重新声明函数();在使用phpunit进行测试时发生,php,testing,phpunit,Php,Testing,Phpunit,我的PHP项目有一些测试。我的测试: class myTests extends PHPunit_Framework_Testcase{ public function testValidateInventoryNumber(){ include('includes/functions.php'); $con = connectToDatabase(); $resultTest1 = validateInventoryNumber("00

我的PHP项目有一些测试。我的测试:

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']);
    }
}
函数
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

我认为这与测试开始时的include有关,因为如果我注释掉其中一个测试,它会正常工作。知道如何修复吗?

多亏了评论中提到的解决方案。而不是
include('includes/functions.php')
,使用
include_一次('includes/functions.php')

您的include()调用。让它包含_once()就这么简单。。。非常感谢,它现在可以工作了!:)