Please tell how to create test cases fro below function to test exception and messages is thrown correctly. I'm using Symfony 2.
public function validateParams(Graph $graph, $start, $destination)
{
if (!is_object($graph)) {
throw new \InvalidArgumentException('Graph param should be an object !');
}
if (empty($start)) {
throw new \InvalidArgumentException('Start param is empty !');
}
if (empty($destination)) {
throw new \InvalidArgumentException('Graph param is empty !');
}
return true;
}
I used below test case and it says, Failed asserting that exception of type "\InvalidArgumentException" is thrown.
/**
* @expectedException \InvalidArgumentException
*/
public function testValidateParamsWhenStartingPointIsEmpty()
{
$this->shortestPathCalc= new ShortestPathCalculator();
$this->shortestPathCalc->validateParams($this->graph, ' ', 'f', 'Expected exception not thrown when starting point is empty !');
}