Skip to content

Commit f8d7f8d

Browse files
committed
add discovered clients functional tests
1 parent eec8c7c commit f8d7f8d

File tree

3 files changed

+84
-1
lines changed

3 files changed

+84
-1
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
namespace Http\HttplugBundle\Tests\Functional;
4+
5+
use Http\Client\Common\PluginClient;
6+
use Http\Client\HttpAsyncClient;
7+
use Http\Client\HttpClient;
8+
use Http\HttplugBundle\Collector\StackPlugin;
9+
use Nyholm\NSA;
10+
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
11+
12+
class DiscoveredClientsTest extends WebTestCase
13+
{
14+
public function testDiscoveredClient()
15+
{
16+
$container = $this->getContainer(false);
17+
18+
$this->assertTrue($container->has('httplug.auto_discovery.auto_discovered_client'));
19+
20+
$service = $container->get('httplug.auto_discovery.auto_discovered_client');
21+
22+
$this->assertInstanceOf(PluginClient::class, $service);
23+
$this->assertInstanceOf(HttpClient::class, NSA::getProperty($service, 'client'));
24+
$this->assertEmpty(NSA::getProperty($service, 'plugins'));
25+
}
26+
27+
public function testDiscoveredAsyncClient()
28+
{
29+
$container = $this->getContainer(false);
30+
31+
$this->assertTrue($container->has('httplug.auto_discovery.auto_discovered_async'));
32+
33+
$service = $container->get('httplug.auto_discovery.auto_discovered_async');
34+
35+
$this->assertInstanceOf(PluginClient::class, $service);
36+
$this->assertInstanceOf(HttpAsyncClient::class, NSA::getProperty($service, 'client'));
37+
$this->assertEmpty(NSA::getProperty($service, 'plugins'));
38+
}
39+
40+
public function testDiscoveredClientWithProfilingEnabled()
41+
{
42+
$container = $this->getContainer(true);
43+
44+
$this->assertTrue($container->has('httplug.auto_discovery.auto_discovered_client'));
45+
46+
$service = $container->get('httplug.auto_discovery.auto_discovered_client');
47+
48+
$this->assertInstanceOf(PluginClient::class, $service);
49+
$this->assertInstanceOf(HttpClient::class, NSA::getProperty($service, 'client'));
50+
51+
$plugins = NSA::getProperty($service, 'plugins');
52+
$this->assertCount(1, $plugins);
53+
$this->assertInstanceOf(StackPlugin::class, $plugins[0]);
54+
$this->assertEquals('auto_discovered_client', NSA::getProperty($plugins[0], 'client'));
55+
}
56+
57+
public function testDiscoveredAsyncClientWithProfilingEnabled()
58+
{
59+
$container = $this->getContainer(true);
60+
61+
$this->assertTrue($container->has('httplug.auto_discovery.auto_discovered_async'));
62+
63+
$service = $container->get('httplug.auto_discovery.auto_discovered_async');
64+
65+
$this->assertInstanceOf(PluginClient::class, $service);
66+
$this->assertInstanceOf(HttpAsyncClient::class, NSA::getProperty($service, 'client'));
67+
68+
$plugins = NSA::getProperty($service, 'plugins');
69+
$this->assertCount(1, $plugins);
70+
$this->assertInstanceOf(StackPlugin::class, $plugins[0]);
71+
$this->assertEquals('auto_discovered_async', NSA::getProperty($plugins[0], 'client'));
72+
}
73+
74+
private function getContainer($debug)
75+
{
76+
static::bootKernel(['debug' => $debug]);
77+
78+
return static::$kernel->getContainer();
79+
}
80+
}

Tests/Resources/app/config/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ framework:
33
test: ~
44

55
httplug:
6+
discovery:
7+
async_client: auto
68
clients:
79
acme:
810
factory: httplug.factory.curl

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
"symfony/finder": "^2.7 || ^3.0",
4646
"symfony/cache": "^3.1",
4747
"polishsymfonycommunity/symfony-mocker-container": "^1.0",
48-
"matthiasnoback/symfony-dependency-injection-test": "^1.0"
48+
"matthiasnoback/symfony-dependency-injection-test": "^1.0",
49+
"nyholm/nsa": "^1.1"
4950
},
5051
"conflict": {
5152
"php-http/guzzle6-adapter": "<1.1"

0 commit comments

Comments
 (0)