Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F1841181
MollieMocksTrait.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
MollieMocksTrait.php
View Options
<?php
namespace
Tests
;
use
GuzzleHttp\Client
;
use
GuzzleHttp\Handler\MockHandler
;
use
GuzzleHttp\HandlerStack
;
use
GuzzleHttp\Middleware
;
use
Mollie\Api\MollieApiClient
;
trait
MollieMocksTrait
{
public
$mollieRequestHistory
=
[];
/**
* Make Mollie's Guzzle instance use a mock handler.
*
* @see http://docs.guzzlephp.org/en/stable/testing.html
*
* @return \GuzzleHttp\Handler\MockHandler
*/
public
function
mockMollie
()
{
$handler
=
HandlerStack
::
create
(
$mockHandler
=
new
MockHandler
()
);
$handler
->
push
(
Middleware
::
history
(
$this
->
mollieRequestHistory
)
);
$guzzle
=
new
Client
([
'handler'
=>
$handler
]);
$this
->
app
->
forgetInstance
(
'mollie.api.client'
);
$this
->
app
->
forgetInstance
(
'mollie.api'
);
$this
->
app
->
forgetInstance
(
'mollie'
);
$this
->
app
->
singleton
(
'mollie.api.client'
,
function
()
use
(
$guzzle
)
{
return
new
MollieApiClient
(
$guzzle
);
});
return
$mockHandler
;
}
public
function
unmockMollie
()
{
$this
->
app
->
forgetInstance
(
'mollie.api.client'
);
$this
->
app
->
forgetInstance
(
'mollie.api'
);
$this
->
app
->
forgetInstance
(
'mollie'
);
$guzzle
=
new
Client
();
$this
->
app
->
singleton
(
'mollie.api.client'
,
function
()
use
(
$guzzle
)
{
return
new
MollieApiClient
(
$guzzle
);
});
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Mon, Aug 25, 2:28 PM (10 h, 26 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
218198
Default Alt Text
MollieMocksTrait.php (1 KB)
Attached To
Mode
R2 kolab
Attached
Detach File
Event Timeline
Log In to Comment