Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -650,9 +650,6 @@ use Http\Client\Common\Plugin;
$this->getClientBuilder()->addPlugin(Plugin $plugin, int $priority): self;
```

> [!NOTE]
> A `PluginException` will be thrown if there is a plugin with the same `priority` level.

It is important to know that this library already uses various plugins with different priorities.
The following list has all the implemented plugins with the respective priority in descending order (remember that order matters):

Expand All @@ -664,6 +661,10 @@ The following list has all the implemented plugins with the respective priority
| [`CachePlugin`](https://docs.php-http.org/en/latest/plugins/cache.html) | 16 | only if cache is enabled |
| [`LoggerPlugin`](https://docs.php-http.org/en/latest/plugins/logger.html) | 8 | only if logger is enabled |

> [!IMPORTANT]
> The plugin priority in the list above is reserved.
> This means that if you try to add any plugin with the same priority, it will be overwritten.

For example, if you wanted the client to automatically attempt to re-send a request that failed
(due to unreliable connections and servers, for example), you can add the [RetryPlugin](https://docs.php-http.org/en/latest/plugins/retry.html):

Expand Down
6 changes: 0 additions & 6 deletions src/Builder/ClientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,6 @@ public function setStreamFactory(StreamFactoryInterface $streamFactory): self

public function addPlugin(Plugin $plugin, int $priority): self
{
if (isset($this->plugins[$priority])) {
throw new PluginException(
sprintf('A plugin with priority %d already exists.', $priority)
);
}

$this->plugins[$priority] = $plugin;
// sort plugins by priority (key) in descending order
krsort($this->plugins);
Expand Down
11 changes: 11 additions & 0 deletions tests/Integration/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ public function testRequest()
$this->assertSame(MockResponse::SUCCESS, $response);
}

public function testMultipleRequests()
{
$this->mockClient->addResponse(new Response(body: MockResponse::SUCCESS));
$this->mockClient->addResponse(new Response(body: MockResponse::SUCCESS));

$this->api->request(method: 'GET', path: '/path-1');
$this->api->request(method: 'GET', path: '/path-2');

$this->assertTrue(true);
}

public function testBaseUrl()
{
$this->assertNull($this->api->getBaseUrl());
Expand Down
5 changes: 2 additions & 3 deletions tests/Unit/Builder/ClientBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,9 @@ public function testAddPluginWithSamePriority()
$plugin = $this->createMock(Plugin::class);
$clientBuilder = new ClientBuilder();

$this->expectException(PluginException::class);
$this->expectExceptionMessage('A plugin with priority 1 already exists.');

$clientBuilder->addPlugin($plugin, 1);
$clientBuilder->addPlugin($plugin, 1);

$this->assertCount(1, $clientBuilder->getPlugins());
}
}