Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F6065350
MollieMocksTrait.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
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
Fri, May 22, 4:35 AM (1 d, 20 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
655369
Default Alt Text
MollieMocksTrait.php (1 KB)
Attached To
Mode
R2 kolab
Attached
Detach File
Event Timeline
Log In to Comment