5
5
use Http \Client \Common \PluginClient ;
6
6
use Http \Client \HttpAsyncClient ;
7
7
use Http \Client \HttpClient ;
8
+ use Http \Discovery \HttpAsyncClientDiscovery ;
9
+ use Http \Discovery \HttpClientDiscovery ;
10
+ use Http \Discovery \Strategy \CommonClassesStrategy ;
8
11
use Http \HttplugBundle \Collector \StackPlugin ;
12
+ use Http \HttplugBundle \Discovery \ConfiguredClientsStrategy ;
9
13
use Nyholm \NSA ;
10
14
use Symfony \Bundle \FrameworkBundle \Test \WebTestCase ;
15
+ use Symfony \Component \EventDispatcher \Event ;
11
16
12
17
class DiscoveredClientsTest extends WebTestCase
13
18
{
@@ -71,6 +76,31 @@ public function testDiscoveredAsyncClientWithProfilingEnabled()
71
76
$ this ->assertEquals ('auto_discovered_async ' , NSA ::getProperty ($ plugins [0 ], 'client ' ));
72
77
}
73
78
79
+ /**
80
+ * Test with httplug.discovery.client: "auto".
81
+ */
82
+ public function testDiscovery ()
83
+ {
84
+ $ container = $ this ->getContainer (true );
85
+
86
+ $ this ->assertTrue ($ container ->has ('httplug.auto_discovery.auto_discovered_client ' ));
87
+ $ this ->assertTrue ($ container ->has ('httplug.auto_discovery.auto_discovered_async ' ));
88
+ $ this ->assertTrue ($ container ->has ('httplug.strategy ' ));
89
+
90
+ $ container ->get ('httplug.strategy ' );
91
+
92
+ $ httpClient = $ container ->get ('httplug.auto_discovery.auto_discovered_client ' );
93
+ $ httpAsyncClient = $ container ->get ('httplug.auto_discovery.auto_discovered_async ' );
94
+
95
+ $ this ->assertInstanceOf (PluginClient::class, $ httpClient );
96
+ $ this ->assertSame (HttpClientDiscovery::find (), $ httpClient );
97
+ $ this ->assertInstanceOf (PluginClient::class, $ httpAsyncClient );
98
+ $ this ->assertSame (HttpAsyncClientDiscovery::find (), $ httpAsyncClient );
99
+ }
100
+
101
+ /**
102
+ * Test with httplug.discovery.client: null.
103
+ */
74
104
public function testDisabledDiscovery ()
75
105
{
76
106
$ container = $ this ->getContainer (true , 'discovery_disabled ' );
@@ -80,6 +110,9 @@ public function testDisabledDiscovery()
80
110
$ this ->assertFalse ($ container ->has ('httplug.strategy ' ));
81
111
}
82
112
113
+ /**
114
+ * Test with httplug.discovery.client: "httplug.client.acme".
115
+ */
83
116
public function testForcedDiscovery ()
84
117
{
85
118
$ container = $ this ->getContainer (true , 'discovery_forced ' );
@@ -88,10 +121,10 @@ public function testForcedDiscovery()
88
121
$ this ->assertFalse ($ container ->has ('httplug.auto_discovery.auto_discovered_async ' ));
89
122
$ this ->assertTrue ($ container ->has ('httplug.strategy ' ));
90
123
91
- $ strategy = $ container ->get ('httplug.strategy ' );
124
+ $ container ->get ('httplug.strategy ' );
92
125
93
- $ this ->assertEquals ($ container ->get ('httplug.client.acme ' ), NSA :: getProperty ( $ strategy , ' client ' ));
94
- $ this ->assertEquals ($ container ->get ('httplug.client.acme ' ), NSA :: getProperty ( $ strategy , ' asyncClient ' ));
126
+ $ this ->assertEquals ($ container ->get ('httplug.client.acme ' ), HttpClientDiscovery:: find ( ));
127
+ $ this ->assertEquals ($ container ->get ('httplug.client.acme ' ), HttpAsyncClientDiscovery:: find ( ));
95
128
}
96
129
97
130
private function getContainer ($ debug , $ environment = 'test ' )
@@ -100,4 +133,14 @@ private function getContainer($debug, $environment = 'test')
100
133
101
134
return static ::$ kernel ->getContainer ();
102
135
}
136
+
137
+ protected function setUp ()
138
+ {
139
+ parent ::setUp ();
140
+
141
+ // Reset values
142
+ $ strategy = new ConfiguredClientsStrategy (null , null , null );
143
+ HttpClientDiscovery::setStrategies ([CommonClassesStrategy::class]);
144
+ $ strategy ->onEvent (new Event ());
145
+ }
103
146
}
0 commit comments