title: How to Achieve Code Coverage for If/Else in PHPUnit?
body: <p>Disclaimer: I'm new to unit testing and just getting my feet wet. That being said, I understand 100% is not always possible, but I'm curious if there is a solution to code coverage with if/else statements such as this or if they are just <em>untestable</em>.</p>
  
  <p><strong>The function:</strong></p>
  
  <pre><code>public function getAll() 
  {
  
      // Query table for all rows sorted by name
      $select = $this-&gt;select();
      $select-&gt;order('name ASC');
      $rowset = $this-&gt;fetchAll($select);
  
      // Validate and return row
      if($rowset-&gt;current())
      {   
          // Return rowset
          return $rowset;
      }
      else { return false; }
  
  }
  </code></pre>
  
  <p><strong>The Unit Test</strong></p>
  
  <pre><code>public function testCanGetAll()
  {
      // Try to get all states
      $result = $this-&gt;model-&gt;getAll();
      $this-&gt;assertNotNull($result);
      $this-&gt;assertNotEquals(false,$result);
  }
  </code></pre>
  
  <p><strong>The Result</strong></p>
  
  <p><img src="https://i.stack.imgur.com/zKF87.png" alt="enter image description here"></p>
  
  <p>As you can see, I can't cover the <code>return false;</code> line. The only way I can think of to test it is to rename my database table or something drastic like that. </p>
  
  <p>Is there another way to write functions with if/else statements (which are a fairly common practice) which allows for easier code coverage? </p>
  
  <p><strong>[EDIT]</strong>
  Perhaps it's better to not check results in the function, and just return it? Whatever calls this function has to do it's own checking?</p>
  
  <pre><code>public function getAll() 
  {
  
      // Query table for all rows sorted by name
      $select = $this-&gt;select();
      $select-&gt;order('name ASC');
      $rowset = $this-&gt;fetchAll($select);
  
      // Return rowset whether valid or not
      return $rowset; 
  
  }
  </code></pre>