Question

i want to write tests for a quite large and complicated project (better later than never).

i made the "code" runnable via bootstrap and tests, but i have some problems with exit commands inside the project ...

i have a testclass like this

class website_call_direct_Test extends PHPUnit_Framework_TestCase
{

   public function execute(array $req){
    $_REQUEST = array();
    error_reporting(E_ALL & ~E_DEPRECATED & ~E_NOTICE & ~E_STRICT);
    foreach($req as $k => $v){
        $_REQUEST[$k] = $v;
    }
    $_GET = &$_REQUEST;
    $_POST = &$_REQUEST;
    ob_start();
    include(G::$baseDir ."/index.php"); 
    $output = ob_get_clean();
    return $output;
}
/**
 * @runInSeparateProcess
 */
public function testPrecaution()
{           
    $req = array();
    $req['ajaxreq'] = 1;
    $req['m'] = "precaution";
    $req['type'] = "list";
    $req['mode'] = "default";
    $req['wnd'] = "new";     
    $output = $this->execute($req);
    echo $output;
    //SOME validation with the output
    $this->assertEquals(false, strpos("...", $output));   
    throw new Exception();
}
}

The Problem is that the Exception is never thrown because the script ends with an exit at several points. i know i can test some classes directly, but i want to ensure that some calls with some variables do not produce errors / exceptions. is there any workaround beside removing every exit in the project?

No correct solution

OTHER TIPS

Looks like you're testing the whole app. I don't think there is any way of disabling the exit sentences.

The workaround (and recommended way of testing whole apps), is accesing the site using curl, and checking that the HTML contains what you expect.

Even better if you use a scraping solution that will let you query the HTML using selectors or XPath, like this one.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top