mockery: Asserting that mock throws exception
Is it possible to configure a mock to throw an exception?
I know this functionality is available in PHPUnit, i.e.:
public function testThrowExceptionStub()
{
// Create a stub for the SomeClass class.
$stub = $this->getMock('SomeClass');
// Configure the stub.
$stub->expects($this->any())
->method('doSomething')
->will($this->throwException(new Exception));
// $stub->doSomething() throws Exception
$stub->doSomething();
}
Is this possible to do using the Mockery API? If not, I can try to create a PR sometime this or next week.
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 20
Yes, there is
->andThrow(...)
method for that.actually you can do this: