jeudi 15 mars 2018

"Fatal error: Cannot redeclare function()" occurs while testing with phpunit

I have some tests for my phpproject. My tests:

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

The functions validateInventoryNumber() and validateLabel() are declared in includes/functions.php, so I need to include this file in both tests, am I right?

If I want to run the testfile, i get the following error:

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

I think it has something to do with the includes at the start of the tests, because if I comment out one of the tests, it works properly. Any idea how it can be fixed?

Aucun commentaire:

Enregistrer un commentaire