mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2024-11-23 21:16:02 +03:00
Close resources on message send http exception
This commit is contained in:
parent
5975310f0e
commit
b27bab7b9f
@ -57,8 +57,11 @@ class Message extends HttpApi
|
|||||||
}
|
}
|
||||||
|
|
||||||
$postDataMultipart = array_merge($this->prepareMultipartParameters($params), $postDataMultipart);
|
$postDataMultipart = array_merge($this->prepareMultipartParameters($params), $postDataMultipart);
|
||||||
$response = $this->httpPostRaw(sprintf('/v3/%s/messages', $domain), $postDataMultipart);
|
try {
|
||||||
$this->closeResources($postDataMultipart);
|
$response = $this->httpPostRaw(sprintf('/v3/%s/messages', $domain), $postDataMultipart);
|
||||||
|
} finally {
|
||||||
|
$this->closeResources($postDataMultipart);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->hydrateResponse($response, SendResponse::class);
|
return $this->hydrateResponse($response, SendResponse::class);
|
||||||
}
|
}
|
||||||
@ -91,8 +94,11 @@ class Message extends HttpApi
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
$postDataMultipart[] = $this->prepareFile('message', $fileData);
|
$postDataMultipart[] = $this->prepareFile('message', $fileData);
|
||||||
$response = $this->httpPostRaw(sprintf('/v3/%s/messages.mime', $domain), $postDataMultipart);
|
try {
|
||||||
$this->closeResources($postDataMultipart);
|
$response = $this->httpPostRaw(sprintf('/v3/%s/messages.mime', $domain), $postDataMultipart);
|
||||||
|
} finally {
|
||||||
|
$this->closeResources($postDataMultipart);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->hydrateResponse($response, SendResponse::class);
|
return $this->hydrateResponse($response, SendResponse::class);
|
||||||
}
|
}
|
||||||
|
@ -124,6 +124,52 @@ class MessageTest extends TestCase
|
|||||||
$api->sendMime('foo', ['mailbox@myapp.com'], $message, []);
|
$api->sendMime('foo', ['mailbox@myapp.com'], $message, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCloseResourcesOnSendRequestException()
|
||||||
|
{
|
||||||
|
$api = $this->getApiMock();
|
||||||
|
|
||||||
|
$api->expects($this->once())
|
||||||
|
->method('httpPostRaw')
|
||||||
|
->willThrowException(new \Exception('Something went wrong'));
|
||||||
|
|
||||||
|
$streamsCount = count(get_resources('stream'));
|
||||||
|
|
||||||
|
try {
|
||||||
|
$api->send('example.com', [
|
||||||
|
'from' => 'bob@example.com',
|
||||||
|
'to' => 'sally@example.com',
|
||||||
|
'subject' => 'Test file path attachments',
|
||||||
|
'text' => 'Test',
|
||||||
|
'attachment' => [
|
||||||
|
['filePath' => __DIR__.'/../TestAssets/mailgun_icon1.png', 'filename' => 'mailgun_icon1.png'],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->assertEquals('Something went wrong', $e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertCount($streamsCount, get_resources('stream'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCloseResourcesOnSendMimeRequestException()
|
||||||
|
{
|
||||||
|
$api = $this->getApiMock();
|
||||||
|
|
||||||
|
$api->expects($this->once())
|
||||||
|
->method('httpPostRaw')
|
||||||
|
->willThrowException(new \Exception('Something went wrong'));
|
||||||
|
|
||||||
|
$streamsCount = count(get_resources('stream'));
|
||||||
|
|
||||||
|
try {
|
||||||
|
$api->sendMime('foo', ['mailbox@myapp.com'], 'mime message', ['o:Foo' => 'bar']);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->assertEquals('Something went wrong', $e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertCount($streamsCount, get_resources('stream'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user