title: testing exceptions with phpunit
body: <p>i am trying to test a function when i know error i going to be thrown. the function looks like this:</p>
  
  <pre><code>function testSetAdsData_dataIsNull(){
      $dataArr = null;
      $fixture = new AdGroup();
  
          try{
              $fixture-&gt;setAdsData($dataArr);
          } catch (Exception $e){
              $this-&gt;assertEquals($e-&gt;getCode(), 2);
          }
  
      $this-&gt;assertEmpty($fixture-&gt;ads);
      $this-&gt;assertEmpty($fixture-&gt;adIds);
  }
  </code></pre>
  
  <p>Now i am trying to use the phpunit exceptions assertions methods to replace the try catch part but i can't figure out how to do that.
  i did lots of reading including this post <a href="https://stackoverflow.com/questions/5683592/phpunit-assert-that-an-exception-was-thrown">PHPUnit assert that an exception was thrown?</a> but i couldnt really understand how it shuold be implemented.</p>
  
  <p>i tried something like this:</p>
  
  <pre><code>/**
   * @expectedException dataIsNull
  
   */
  
  function testSetAdsData_dataIsNull(){
      $dataArr = null;
      $fixture = new AdGroup();
  
      $this-&gt;setExpectedException('dataIsNull');
      $fixture-&gt;setAdsData($dataArr);
      $this-&gt;assertEmpty($fixture-&gt;ads);
      $this-&gt;assertEmpty($fixture-&gt;adIds);
  }
  
  but obviously it didn't work  and i got this error:
  1) adGroupTest::testSetAdsData_dataIsNull
  ReflectionException: Class dataIsNull does not exist
  </code></pre>
  
  <p>what am i doing wrong and how exactly can i assert if exception was thrown plz? </p>