Skip to content

[2.0] Remove plugin chain debug #119

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 0 additions & 43 deletions spec/PluginClientSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,47 +87,4 @@ function it_throws_loop_exception(HttpClient $httpClient, RequestInterface $requ

$this->shouldThrow('Http\Client\Common\Exception\LoopException')->duringSendRequest($request);
}

function it_injects_debug_plugins(HttpClient $httpClient, ResponseInterface $response, RequestInterface $request, Plugin $plugin0, Plugin $plugin1, Plugin $debugPlugin)
{
$plugin0
->handleRequest(
$request,
Argument::type('callable'),
Argument::type('callable')
)
->shouldBeCalledTimes(1)
->will(function ($args) {
return $args[1]($args[0]);
})
;
$plugin1
->handleRequest(
$request,
Argument::type('callable'),
Argument::type('callable')
)
->shouldBeCalledTimes(1)
->will(function ($args) {
return $args[1]($args[0]);
})
;

$debugPlugin
->handleRequest(
$request,
Argument::type('callable'),
Argument::type('callable')
)
->shouldBeCalledTimes(3)
->will(function ($args) {
return $args[1]($args[0]);
})
;

$httpClient->sendRequest($request)->willReturn($response);

$this->beConstructedWith($httpClient, [$plugin0, $plugin1], ['debug_plugins'=>[$debugPlugin]]);
$this->sendRequest($request);
}
}
12 changes: 1 addition & 11 deletions src/PluginClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ final class PluginClient implements HttpClient, HttpAsyncClient
* @param array $options {
*
* @var int $max_restarts
* @var Plugin[] $debug_plugins an array of plugins that are injected between each normal plugin
* }
*
* @throws \RuntimeException if client is not an instance of HttpClient or HttpAsyncClient
Expand Down Expand Up @@ -131,16 +130,7 @@ private function createPluginChain($pluginList, callable $clientCallable)
{
$firstCallable = $lastCallable = $clientCallable;

/*
* Inject debug plugins between each plugin.
*/
$pluginListWithDebug = $this->options['debug_plugins'];
foreach ($pluginList as $plugin) {
$pluginListWithDebug[] = $plugin;
$pluginListWithDebug = array_merge($pluginListWithDebug, $this->options['debug_plugins']);
}

while ($plugin = array_pop($pluginListWithDebug)) {
while ($plugin = array_pop($pluginList)) {
$lastCallable = function (RequestInterface $request) use ($plugin, $lastCallable, &$firstCallable) {
return $plugin->handleRequest($request, $lastCallable, $firstCallable);
};
Expand Down