title: Force PHPUnit test to throw exception
body: <p>I'm very new to unit testing in general and PHPUnit in particular, so please forgive me if this is a simple question. I have done some googling, but I don't know enough to know what to search for.</p>
  
  <p>So I have a function:</p>
  
  <pre><code>function convert_timezone($dt, $tzFrom, $tzTo, $format) {
      $newDate = '';
  
      $tzFromFull = timezone_name_from_abbr($tzFrom);
      $tzToFull = timezone_name_from_abbr($tzTo);
  
      if( $tzFromFull != $tzToFull ) {
          $dtFrom = new DateTimeZone($tzFromFull);
          $dtTo = new DateTimeZone($tzToFull);
  
          try {
              // find the offsets from GMT for the 2 timezones
              $current = new DateTime(date('c',$dt));
              $offset1 = $dtFrom-&gt;getOffset($current);
              $offset2 = $dtTo-&gt;getOffset($current);
              $offset = $offset2 - $offset1;
  
              // apply the offset difference to the current time
              $newDate = date($format, $current-&gt;format('U') + $offset);
          } catch (Exception $e) {
              $newDate = date($format.' (T)', $dt);
          }
      } else {
          $newDate = date($format, $dt);
      }
  
      return $newDate;
  }
  </code></pre>
  
  <p>Here's the test function:</p>
  
  <pre><code>function test_convert_timezone() {
     $dt = mktime(0,0,0,1,1,2000);
     $tzFrom = 'CDT';
     $tzTo = 'EDT';
     $format = 'd/m/Y g:i a';
     $result = convert_timezone($dt, $tzFrom, $tzTo, $format);
     $this-&gt;assertEquals($result, '01/01/2000 1:00 am');
  }
  </code></pre>
  
  <p>When I run the tests directly in Netbeans, the test passes. But when I use the command-line option to generate a code coverage report, it tells me that this function is not completely covered because the test isn't hitting the exception. </p>
  
  <p>I know if I could alter the original function, I could force it to throw an error. But I can't do that. I need a way, in the test function, to pass something in that will make the function being tested hit its exception. Where do I start?</p>