This is the method that i want to test:
class a {
public function method($args) {
if($args == "xxx") {
throw new MyException("Right Message");
}
}
The problem is that Myexception.php is not available, so i should create a mock of MyException and redifine the exception, this is my solution but doesn't work. thanks
/**
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Right Message
*/
public function testSubscribeCommunity(){
$MyException = $this->getMockBuilder('MyException')
->setMethods(array('__construct'))
->setConstructorArgs(array('Right Message'))
->disableOriginalConstructor()
->getMock();
$MyException->method('__construct')
->will($this->throwException(new InvalidArgumentException));
$objectToTest = new A();
$objectToTest->method(null,$args);
}