Fix api transport mult-line parsing (#13469)

* API transport fix parsing
parse templates after parsing user options, not before

* API transport tests

* fix style and lint

* remove accidental item

* fix more type issues
This commit is contained in:
Tony Murray
2021-11-03 13:37:57 -05:00
committed by GitHub
parent 01345b5fba
commit 0862496e26
8 changed files with 239 additions and 48 deletions

View File

@@ -0,0 +1,80 @@
<?php
namespace LibreNMS\Tests\Traits;
use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
/**
* @mixin \LibreNMS\Tests\TestCase
*/
trait MockGuzzleClient
{
/**
* @var MockHandler
*/
private $guzzleMockHandler;
/**
* @var array
*/
private $guzzleConfig;
/**
* @var array
*/
private $guzzleHistory = [];
/**
* Create a Guzzle MockHandler and bind Client with the handler to the Laravel container
*
* @param array $queue Sequential Responses to give to the client.
* @param array $config Guzzle config settings.
*/
public function mockGuzzleClient(array $queue, array $config = []): MockHandler
{
$this->guzzleConfig = $config;
$this->guzzleMockHandler = new MockHandler($queue);
$this->app->bind(Client::class, function () {
$handlerStack = HandlerStack::create($this->guzzleMockHandler);
$handlerStack->push(Middleware::history($this->guzzleHistory));
return new Client(array_merge($this->guzzleConfig, ['handler' => $handlerStack]));
});
return $this->guzzleMockHandler;
}
/**
* Get the request and response history to inspect
*
* @return array
*/
public function guzzleHistory(): array
{
return $this->guzzleHistory;
}
/**
* Get the request history to inspect
*
* @return \GuzzleHttp\Psr7\Request[]
*/
public function guzzleRequestHistory(): array
{
return array_column($this->guzzleHistory, 'request');
}
/**
* Get the response history to inspect
*
* @return \GuzzleHttp\Psr7\Response[]
*/
public function guzzleResponseHistory(): array
{
return array_column($this->guzzleHistory, 'response');
}
}