Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble Building a Simpletest Suite From Working Unit Test Cases

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?

like image 989
Brian Bauman Avatar asked Nov 05 '22 13:11

Brian Bauman


1 Answers

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' );
like image 145
Justin ᚅᚔᚈᚄᚒᚔ Avatar answered Nov 15 '22 08:11

Justin ᚅᚔᚈᚄᚒᚔ