Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F49506723
WithMockHttpClient.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
789 B
Referenced Files
None
Subscribers
None
WithMockHttpClient.php
View Options
<?php
namespace
Keruald\DockerHub\Tests
;
use
GuzzleHttp\Client
;
use
GuzzleHttp\HandlerStack
;
use
GuzzleHttp\Handler\MockHandler
;
use
GuzzleHttp\Psr7\Response
;
trait
WithMockHttpClient
{
/**
* Mocks HTTP client
*
* @param int $httpResponseCode The HTTP response code to mock
* @return \GuzzleHttp\Client
*/
protected
static
function
mockHttpClient
(
$httpResponseCode
=
200
)
{
$handler
=
self
::
getCustomMockHttpClientHandler
(
$httpResponseCode
);
return
new
Client
([
'handler'
=>
$handler
]);
}
/**
* @return \GuzzleHttp\HandlerStack
*/
protected
static
function
getCustomMockHttpClientHandler
(
$code
)
{
return
HandlerStack
::
create
(
new
MockHandler
([
new
Response
(
$code
),
]));
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Mon, Sep 14, 16:03 (10 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4085828
Default Alt Text
WithMockHttpClient.php (789 B)
Attached To
Mode
rKDOCKERHUB Keruald Docker Hub
Attached
Detach File
Event Timeline
Log In to Comment