Code coverage with phpunit; can't get to one place.

Posted by HA17 on Stack Overflow See other posts from Stack Overflow or by HA17
Published on 2010-03-16T15:05:39Z Indexed on 2010/03/16 15:11 UTC
Read the original article Hit count: 182

Filed under:
|
|

In the xdebug code coverage, it shows the line "return false;" (below "!$r") as not covered by my tests. But, the $sql is basically hard-coded. How do I get coverage on that? Do I overwrite "$table" somehow? Or kill the database server for this part of the test?

I guess this is probably telling me I'm not writing my model very well, right? Because I can't test it well. How can I write this better?

Since this one line is not covered, the whole method is not covered and the reports are off.

I'm fairly new to phpunit. Thanks.


public function retrieve_all()
{
    $table = $this->tablename();
    $sql     = "SELECT t.* FROM `{$table}` as t";
    $r         = dbq ( $sql, 'read' );

    if(!$r)
    {
        return false;
    }

    $ret = array ();

    while ( $rs    = mysql_fetch_array ( $r, MYSQL_ASSOC ) )
    {
        $ret[] = $rs;
    }


    return $ret;
}

© Stack Overflow or respective owner

Related posts about phpunit

Related posts about php