-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathPluginClientBuilderTest.php
82 lines (64 loc) · 2.14 KB
/
PluginClientBuilderTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
declare(strict_types=1);
namespace Tests\Http\Client\Common;
use Http\Client\Common\Plugin;
use Http\Client\Common\PluginClient;
use Http\Client\Common\PluginClientBuilder;
use Http\Client\HttpAsyncClient;
use Http\Client\HttpClient;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
class PluginClientBuilderTest extends TestCase
{
use ProphecyTrait;
/** @dataProvider clientProvider */
public function testPriority(string $client): void
{
$builder = new PluginClientBuilder();
$plugins = [
10 => $this->prophesize(Plugin::class)->reveal(),
-10 => $this->prophesize(Plugin::class)->reveal(),
0 => $this->prophesize(Plugin::class)->reveal(),
];
foreach ($plugins as $priority => $plugin) {
$builder->addPlugin($plugin, $priority);
}
$client = $this->prophesize($client)->reveal();
$client = $builder->createClient($client);
$closure = \Closure::bind(
function (): array {
return $this->plugins;
},
$client,
PluginClient::class
);
$plugged = $closure();
$expected = $plugins;
krsort($expected);
$expected = array_values($expected);
$this->assertSame($expected, $plugged);
}
/** @dataProvider clientProvider */
public function testOptions(string $client): void
{
$builder = new PluginClientBuilder();
$builder->setOption('max_restarts', 5);
$client = $this->prophesize($client)->reveal();
$client = $builder->createClient($client);
$closure = \Closure::bind(
function (): array {
return $this->options;
},
$client,
PluginClient::class
);
$options = $closure();
$this->assertArrayHasKey('max_restarts', $options);
$this->assertSame(5, $options['max_restarts']);
}
public static function clientProvider(): iterable
{
yield 'sync\'d http client' => [HttpClient::class];
yield 'async\'d http client' => [HttpAsyncClient::class];
}
}