title: Unit test that exception is thrown on nth call to function
body: <p>Say you have a method which ultimately boils down to</p>
  
  <pre class="lang-php prettyprint-override"><code>class Pager
  {
      private $i;
  
      public function next()
      {
          if ($this-&gt;i &gt;= 3) {
              throw new OutOfBoundsException();
          }
  
          $this-&gt;i++;
      }
  }
  </code></pre>
  
  <p>How would you unit test this class. I.e. test whether the exception gets thrown on the third call of <code>next()</code> using PHPUnit? I've added my attempt as an answer, but I'm not sure whether this really is the way to go.</p>