|
@@ -10,6 +10,7 @@ use App\Auth\OidcAuthenticator;
|
|
|
use GuzzleHttp\ClientInterface as GuzzleClientInterface;
|
|
use GuzzleHttp\ClientInterface as GuzzleClientInterface;
|
|
|
use GuzzleHttp\Handler\MockHandler;
|
|
use GuzzleHttp\Handler\MockHandler;
|
|
|
use GuzzleHttp\HandlerStack;
|
|
use GuzzleHttp\HandlerStack;
|
|
|
|
|
+use GuzzleHttp\Middleware;
|
|
|
use Monolog\Handler\NullHandler;
|
|
use Monolog\Handler\NullHandler;
|
|
|
use Monolog\Logger;
|
|
use Monolog\Logger;
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use PHPUnit\Framework\TestCase;
|
|
@@ -32,6 +33,8 @@ abstract class AppTestCase extends TestCase
|
|
|
protected ContainerInterface $container;
|
|
protected ContainerInterface $container;
|
|
|
protected App $app;
|
|
protected App $app;
|
|
|
protected MockHandler $mock;
|
|
protected MockHandler $mock;
|
|
|
|
|
+ /** @var list<array{request: \Psr\Http\Message\RequestInterface, response: \Psr\Http\Message\ResponseInterface, error: mixed, options: array<string, mixed>}> */
|
|
|
|
|
+ protected array $apiHistory = [];
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @param array<string, mixed> $overrides
|
|
* @param array<string, mixed> $overrides
|
|
@@ -64,11 +67,13 @@ abstract class AppTestCase extends TestCase
|
|
|
|
|
|
|
|
$this->container = Container::build($settings);
|
|
$this->container = Container::build($settings);
|
|
|
$this->mock = new MockHandler();
|
|
$this->mock = new MockHandler();
|
|
|
|
|
+ $this->apiHistory = [];
|
|
|
|
|
|
|
|
if (method_exists($this->container, 'set')) {
|
|
if (method_exists($this->container, 'set')) {
|
|
|
/** @var \DI\Container $c */
|
|
/** @var \DI\Container $c */
|
|
|
$c = $this->container;
|
|
$c = $this->container;
|
|
|
$handler = HandlerStack::create($this->mock);
|
|
$handler = HandlerStack::create($this->mock);
|
|
|
|
|
+ $handler->push(Middleware::history($this->apiHistory));
|
|
|
$c->set(GuzzleClientInterface::class, new \GuzzleHttp\Client(['handler' => $handler]));
|
|
$c->set(GuzzleClientInterface::class, new \GuzzleHttp\Client(['handler' => $handler]));
|
|
|
// ApiClient closure-builds from the container; refresh the
|
|
// ApiClient closure-builds from the container; refresh the
|
|
|
// bound instance with our mocked Guzzle client.
|
|
// bound instance with our mocked Guzzle client.
|