Got a basic question about handling Exceptions in Magento 2. I'm currently on Magento 2.2 with PHPUnit 6.2.4. I would like to write a test for a CouldNotSaveException.
Got the following code example
try {
$this->customerDataResource->save($customerDataObject);
} catch (\Exception $e) {
throw new CouldNotSaveException(new Phrase(
'Unable to save customer with ID '. $customerData->getCustomerId()
));
}
Currently got the following usage from PHPUnit documentation
/**
* Test save() method when exception is thrown
*/
public function testSaveException()
{
$this->expectException(CouldNotSaveException::class);
}
I'm mocking my objects using the createMock()
method. Don't really know how to write the rest of the code.
If someone could help me out that would be great. Thanks in advance!