File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed
Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -104,10 +104,10 @@ public function __construct(array $config)
104104 $ this ->logger = new Logger ('typesense ' );
105105 $ this ->logger ->pushHandler (new StreamHandler ('php://stdout ' , $ this ->logLevel ));
106106
107- if (true === \array_key_exists ( 'client ' , $ config )) {
108- if ($ config ['client ' ] instanceof HttpMethodsClient) {
107+ if (isset ( $ config [ 'client ' ] )) {
108+ if ($ config ['client ' ] instanceof HttpMethodsClient || $ config [ ' client ' ] instanceof ClientInterface ) {
109109 $ this ->client = $ config ['client ' ];
110- } elseif ($ config ['client ' ] instanceof HttpClient || $ config [ ' client ' ] instanceof ClientInterface ) {
110+ } elseif ($ config ['client ' ] instanceof HttpClient) {
111111 $ this ->client = new HttpMethodsClient (
112112 $ config ['client ' ],
113113 Psr17FactoryDiscovery::findRequestFactory (),
Original file line number Diff line number Diff line change @@ -38,8 +38,13 @@ public function testWorksWithDefaultClient(): void
3838 public function testWorksWithPsr18Client (): void
3939 {
4040 $ httpClient = new Psr18Client ();
41- $ config = array_merge ($ this ->baseConfig , ['client ' => $ httpClient ]);
41+ $ wrappedClient = new HttpMethodsClient (
42+ $ httpClient ,
43+ Psr17FactoryDiscovery::findRequestFactory (),
44+ Psr17FactoryDiscovery::findStreamFactory ()
45+ );
4246
47+ $ config = array_merge ($ this ->baseConfig , ['client ' => $ wrappedClient ]);
4348 $ client = new Client ($ config );
4449 $ response = $ client ->health ->retrieve ();
4550 $ this ->assertIsBool ($ response ['ok ' ]);
@@ -60,6 +65,14 @@ public function testWorksWithHttpMethodsClient(): void
6065 $ this ->assertIsBool ($ response ['ok ' ]);
6166 }
6267
68+ public function testWorksWithLegacyPsr18Client (): void
69+ {
70+ $ httpClient = $ this ->createMock (\Psr \Http \Client \ClientInterface::class);
71+ $ config = array_merge ($ this ->baseConfig , ['client ' => $ httpClient ]);
72+ $ client = new Client ($ config );
73+ $ this ->assertInstanceOf (Client::class, $ client );
74+ }
75+
6376 public function testRejectsInvalidClient (): void
6477 {
6578 $ this ->expectException (ConfigError::class);
You can’t perform that action at this time.
0 commit comments