Changeset View
Changeset View
Standalone View
Standalone View
src/tests/CoinbaseMocksTrait.php
- This file was added.
<?php | |||||
namespace Tests; | |||||
use GuzzleHttp\Client; | |||||
use GuzzleHttp\Handler\MockHandler; | |||||
use GuzzleHttp\HandlerStack; | |||||
use GuzzleHttp\Middleware; | |||||
trait CoinbaseMocksTrait | |||||
{ | |||||
public $coinbaseRequestHistory = []; | |||||
/** | |||||
* Make Coinbase's Guzzle instance use a mock handler. | |||||
* | |||||
* @see http://docs.guzzlephp.org/en/stable/testing.html | |||||
* | |||||
* @return \GuzzleHttp\Handler\MockHandler | |||||
*/ | |||||
public function mockCoinbase() | |||||
{ | |||||
$handler = HandlerStack::create( | |||||
$mockHandler = new MockHandler() | |||||
); | |||||
$handler->push( | |||||
Middleware::history($this->coinbaseRequestHistory) | |||||
); | |||||
\App\Providers\Payment\Coinbase::$testClient = new Client(['handler' => $handler]); | |||||
machniak: We should start using https://laravel.com/docs/9.x/http-client | |||||
Done Inline ActionsLet's do that separately mollekopf: Let's do that separately | |||||
return $mockHandler; | |||||
} | |||||
public function unmockCoinbase() | |||||
{ | |||||
\App\Providers\Payment\Coinbase::$testClient = null; | |||||
} | |||||
} |
We should start using https://laravel.com/docs/9.x/http-client