Skip to content

Commit 5dc5ba1

Browse files
committed
fix: multiple requests
1 parent d44459d commit 5dc5ba1

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -650,9 +650,6 @@ use Http\Client\Common\Plugin;
650650
$this->getClientBuilder()->addPlugin(Plugin $plugin, int $priority): self;
651651
```
652652

653-
> [!NOTE]
654-
> A `PluginException` will be thrown if there is a plugin with the same `priority` level.
655-
656653
It is important to know that this library already uses various plugins with different priorities.
657654
The following list has all the implemented plugins with the respective priority in descending order (remember that order matters):
658655

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

664+
> [!IMPORTANT]
665+
> The plugin priority in the list above is reserved.
666+
> This means that if you try to add any plugin with the same priority, it will be overwritten.
667+
667668
For example, if you wanted the client to automatically attempt to re-send a request that failed
668669
(due to unreliable connections and servers, for example), you can add the [RetryPlugin](https://docs.php-http.org/en/latest/plugins/retry.html):
669670

src/Builder/ClientBuilder.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,6 @@ public function setStreamFactory(StreamFactoryInterface $streamFactory): self
7373

7474
public function addPlugin(Plugin $plugin, int $priority): self
7575
{
76-
if (isset($this->plugins[$priority])) {
77-
throw new PluginException(
78-
sprintf('A plugin with priority %d already exists.', $priority)
79-
);
80-
}
81-
8276
$this->plugins[$priority] = $plugin;
8377
// sort plugins by priority (key) in descending order
8478
krsort($this->plugins);

tests/Integration/ApiTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,17 @@ public function testRequest()
5050
$this->assertSame(MockResponse::SUCCESS, $response);
5151
}
5252

53+
public function testMultipleRequests()
54+
{
55+
$this->mockClient->addResponse(new Response(body: MockResponse::SUCCESS));
56+
$this->mockClient->addResponse(new Response(body: MockResponse::SUCCESS));
57+
58+
$this->api->request(method: 'GET', path: '/path-1');
59+
$this->api->request(method: 'GET', path: '/path-2');
60+
61+
$this->assertTrue(true);
62+
}
63+
5364
public function testBaseUrl()
5465
{
5566
$this->assertNull($this->api->getBaseUrl());

tests/Unit/Builder/ClientBuilderTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,9 @@ public function testAddPluginWithSamePriority()
7777
$plugin = $this->createMock(Plugin::class);
7878
$clientBuilder = new ClientBuilder();
7979

80-
$this->expectException(PluginException::class);
81-
$this->expectExceptionMessage('A plugin with priority 1 already exists.');
82-
8380
$clientBuilder->addPlugin($plugin, 1);
8481
$clientBuilder->addPlugin($plugin, 1);
82+
83+
$this->assertCount(1, $clientBuilder->getPlugins());
8584
}
8685
}

0 commit comments

Comments
 (0)