i am trying to test a function when i know error i going to be thrown. the function looks like this:
function testSetAdsData_dataIsNull(){
$dataArr = null;
$fixture = new AdGroup();
try{
$fixture->setAdsData($dataArr);
} catch (Exception $e){
$this->assertEquals($e->getCode(), 2);
}
$this->assertEmpty($fixture->ads);
$this->assertEmpty($fixture->adIds);
}
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 PHPUnit assert that an exception was thrown? but i couldnt really understand how it shuold be implemented.
i tried something like this:
/**
* @expectedException dataIsNull
*/
function testSetAdsData_dataIsNull(){
$dataArr = null;
$fixture = new AdGroup();
$this->setExpectedException('dataIsNull');
$fixture->setAdsData($dataArr);
$this->assertEmpty($fixture->ads);
$this->assertEmpty($fixture->adIds);
}
but obviously it didn't work and i got this error:
1) adGroupTest::testSetAdsData_dataIsNull
ReflectionException: Class dataIsNull does not exist
what am i doing wrong and how exactly can i assert if exception was thrown plz?