title: How to test exceptions using a data provider in PHPUnit?
body: <p>PHPUnit has a very useful feature <a href="https://phpunit.de/manual/current/en/writing-tests-for-phpunit.html#writing-tests-for-phpunit.data-providers.examples.DataTest.php" rel="noreferrer"><code>@dataProvider</code></a>, that allows to test multiple cases of a method. It also has another cool annotation -- <a href="https://phpunit.de/manual/current/en/writing-tests-for-phpunit.html#writing-tests-for-phpunit.exceptions.examples.ExceptionTest2.php" rel="noreferrer"><code>@expectedException</code></a> to ensure the application throws a correct <code>Exception</code> at a defined place.</p>
  
  <p>I'm currently testing a method against multiple edge cases and would like to combine these two features like this (not working code):</p>
  
  <pre><code>class TestMyClass
  {
      /**
       * @dataProvider provideDataForFoo
       */
      public function testFoo($paramBar, $paramBuz, $expected)
      {
          $myObject = new MyClass();
          $this-&gt;assertEquals($expected, $myObject-&gt;foo($paramBar, $paramBuz));
      }
      public function provideDataForFoo()
      {
          return [
              ['expected lorem', 'bar lorem', 'buz lorem'],
              ['expected ipsum', 'bar ipsum', 'buz ipsum'],
              ['expected exception', 'bar invalid argument', 'buz invalid argument'],
          ];
      }
  }
  </code></pre>
  
  <p><strong>Is possible / How to use <code>@expectedException</code> as one of the cases, when using <code>@dataProvider</code>?</strong></p>