Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F35072977
WithMockHttpClient.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
WithMockHttpClient.php
View Options
<?php
namespace
Keruald\Mailgun\Tests
;
use
GuzzleHttp\Client
;
use
GuzzleHttp\HandlerStack
;
use
GuzzleHttp\Handler\MockHandler
;
use
GuzzleHttp\Psr7\Response
;
trait
WithMockHttpClient
{
/**
* @return \GuzzleHttp\
*/
public
function
mockHttpClient
()
{
$body
=
$this
->
mockHttpClientResponseBody
();
return
self
::
mockHttpClientWithCustomResponse
(
200
,
$body
);
}
/**
* @return \GuzzleHttp\Client
*/
public
function
mockHttpClientWithCustomResponse
(
$code
,
$body
)
{
$handler
=
self
::
getCustomMockHttpClientHandler
(
$code
,
$body
);
return
new
Client
([
'handler'
=>
$handler
]);
}
/**
* @return stdClass
*/
public
function
mockEventPayload
()
{
return
json_decode
(
file_get_contents
(
__DIR__
.
'/payload.json'
));
}
///
/// Mock helper methods
///
/**
* @return \GuzzleHttp\HandlerStack
*/
protected
static
function
getCustomMockHttpClientHandler
(
$code
,
$body
,
$headers
=
[])
{
return
HandlerStack
::
create
(
new
MockHandler
([
new
Response
(
$code
,
$headers
,
$body
),
]));
}
/**
* @return string
*/
protected
static
function
mockHttpClientResponseBody
()
{
return
file_get_contents
(
__DIR__
.
'/response.json'
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Wed, Jul 8, 15:03 (23 h, 18 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3903895
Default Alt Text
WithMockHttpClient.php (1 KB)
Attached To
Mode
rKMAILGUN Keruald Mailgun
Attached
Detach File
Event Timeline
Log In to Comment