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)
104
104
$ this ->logger = new Logger ('typesense ' );
105
105
$ this ->logger ->pushHandler (new StreamHandler ('php://stdout ' , $ this ->logLevel ));
106
106
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 ) {
109
109
$ this ->client = $ config ['client ' ];
110
- } elseif ($ config ['client ' ] instanceof HttpClient || $ config [ ' client ' ] instanceof ClientInterface ) {
110
+ } elseif ($ config ['client ' ] instanceof HttpClient) {
111
111
$ this ->client = new HttpMethodsClient (
112
112
$ config ['client ' ],
113
113
Psr17FactoryDiscovery::findRequestFactory (),
Original file line number Diff line number Diff line change @@ -38,8 +38,13 @@ public function testWorksWithDefaultClient(): void
38
38
public function testWorksWithPsr18Client (): void
39
39
{
40
40
$ httpClient = new Psr18Client ();
41
- $ config = array_merge ($ this ->baseConfig , ['client ' => $ httpClient ]);
41
+ $ wrappedClient = new HttpMethodsClient (
42
+ $ httpClient ,
43
+ Psr17FactoryDiscovery::findRequestFactory (),
44
+ Psr17FactoryDiscovery::findStreamFactory ()
45
+ );
42
46
47
+ $ config = array_merge ($ this ->baseConfig , ['client ' => $ wrappedClient ]);
43
48
$ client = new Client ($ config );
44
49
$ response = $ client ->health ->retrieve ();
45
50
$ this ->assertIsBool ($ response ['ok ' ]);
@@ -60,6 +65,14 @@ public function testWorksWithHttpMethodsClient(): void
60
65
$ this ->assertIsBool ($ response ['ok ' ]);
61
66
}
62
67
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
+
63
76
public function testRejectsInvalidClient (): void
64
77
{
65
78
$ this ->expectException (ConfigError::class);
You can’t perform that action at this time.
0 commit comments