5

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?

2
  • 4
    Your include() calls. Make it include_once() Commented Mar 15, 2018 at 12:19
  • Simple as that... Thank you so much, it works now! :) Commented Mar 15, 2018 at 12:21

1 Answer 1

3

Thanks to @Karlo Kokkakwho mentioned the solution in the comments. Instead of include('includes/functions.php');, use include_once('includes/functions.php');.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.