I've started using unit testing for my PHP programs, and figured Simpletest was as good a place to dive in as any other. I added the Simpletest files to my testing server, and ran the following tests on my custom PDO classes:
<?php
require_once('../simpletest/autorun.php');
require_once('../includes/inc_sql.php');
class TestOfSQL extends UnitTestCase{
function testRead(){
...
}
function testWriteAndDelete(){
...
}
}
?>
That all works out smashingly. I try to build a test suite involving (so far) just that testing file, as follows:
<?php
require_once('../simpletest/autorun.php');
class AllTests extends TestSuite {
function __construct(){
parent::__construct();
$this->addFile('inc_sql_test.php');
}
}
This crashes and burns, and I get the following readout:
Warning: include_once(inc_sql_test.php) [function.include-once]: failed to open stream: No such file or directory in E:\xampp\htdocs\historicMuncie\simpletest\test_case.php on line 382
Warning: include_once() [function.include]: Failed opening 'inc_sql_test.php' for inclusion (include_path='.;E:\xampp\php\PEAR') in E:\xampp\htdocs\historicMuncie\simpletest\test_case.php on line 382
Warning: file_get_contents(inc_sql_test.php) [function.file-get-contents]: failed to open stream: No such file or directory in E:\xampp\htdocs\historicMuncie\simpletest\test_case.php on line 418
all_tests.php
Fail: AllTests -> inc_sql_test.php -> Bad TestSuite [inc_sql_test.php] with error [No runnable test cases in [inc_sql_test.php]]
0/0 test cases complete: 0 passes, 1 fails and 0 exceptions.
I've played around with include paths, web root vs. server root notation - anything that came to mind, but nothing is allowing that test suite to run properly. Any ideas?
I always cringe when I see relative paths in PHP scripts. It's much easier to implement and maintain when using "semi-absolute" paths based on a common root. Try:
$this->addFile( $_SERVER['DOCUMENT_ROOT'] . '/inc_sql_test.php' );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With