A Simpletest test in MyTest.php that runs with no errors:
require_once ('simpletest/autorun.php');
class MyTest extends UnitTestCase {
function test() {
//Test...
}
}
A SimpleTest test suite
require_once ('simpletest/autorun.php');
class AllTests extends TestSuite {
function __construct() {
$this->TestSuite('All tests');
$this->addFile('MyTest.php');
}
}
The error:
Fatal error: Cannot redeclare simpletest_autorun() (previously declared in /Library/WebServer/Documents/Option/tests/simpletest/autorun.php:26) in /Library/WebServer/Documents/option/tests/simpletest/autorun.php on line 34
The (horrible) solution, change MyTest.php to:
if (!function_exists("simpletest_autorun")) {
require_once ('simpletest/autorun.php');
}
class MyTest extends UnitTestCase {
function test() {
//Test...
}
}
It appears that this example follows the documentation, it doesn't or SimpleTest has this bug?
I can only assume you have multiple copies of the SimpleTest autorun.php
script.
Performing the require
in your test case file attempts to include a second autorun.php
file (different to the one included in your test suite) which defines simpletest_autorun()
for the second time.
The fact that the line numbers don't match up adds credence to my assumption.
Looking at the full paths in the error messages should show you what's up.
Determine which copy you want to keep and remove the other, updating any incorrect paths in your code or configuration, including the include_path
in php.ini
.