title: test the return value of a method that triggers an error with PHPUnit
body: <p>This question is specific to using PHPUnit.</p>
  
  <p>PHPUnit automatically converts php errors to exceptions. <strong>Is there a way to test the return value of a method that happens to trigger a php error (either built-in errors or user generated errors via <em>trigger_error</em>)?</strong></p>
  
  <p>Example of code to test:</p>
  
  <pre><code>function load_file ($file)
  {
      if (! file_exists($file)) {
          trigger_error("file {$file} does not exist", E_USER_WARNING);
          return false;
      }
      return file_get_contents($file);
  }
  </code></pre>
  
  <p>This is the type of test I want to write:</p>
  
  <pre><code>public function testLoadFile ()
  {
      $this-&gt;assertFalse(load_file('/some/non-existent/file'));
  }
  </code></pre>
  
  <p>The problem I am having is that the triggered error causes my unit test to fail (as it should). But if I try to catch it, or set an expected exception any code that after the error is triggered never executes so I have no way of testing the return value of the method.</p>
  
  <p>This example doesn't work:</p>
  
  <pre><code>public function testLoadFile ()
  {
      $this-&gt;setExpectedException('Exception');
      $result = load_file('/some/non-existent/file');
  
      // code after this point never gets executed
  
      $this-&gt;assertFalse($result);
  }
  </code></pre>
  
  <p>Any ideas how I could achieve this?</p>