@@ -296,4 +296,52 @@ public function testElasticClientMetaHeaderIsNotSentWhenDisabled()
296296 $ this ->assertFalse (isset ($ request ['request ' ]['headers ' ]['x-elastic-client-meta ' ]));
297297 }
298298 }
299+
300+ public function getCompatibilityHeaders ()
301+ {
302+ return [
303+ ['true ' , true ],
304+ ['1 ' , true ],
305+ ['false ' , false ],
306+ ['0 ' , false ]
307+ ];
308+ }
309+
310+ /**
311+ * @dataProvider getCompatibilityHeaders
312+ */
313+ public function testCompatibilityHeader ($ env , $ compatibility )
314+ {
315+ putenv ("ELASTIC_CLIENT_APIVERSIONING= $ env " );
316+
317+ $ client = ClientBuilder::create ()
318+ ->build ();
319+
320+ try {
321+ $ result = $ client ->info ();
322+ } catch (ElasticsearchException $ e ) {
323+ $ request = $ client ->transport ->getLastConnection ()->getLastRequestInfo ();
324+ if ($ compatibility ) {
325+ $ this ->assertContains ('application/vnd.elasticsearch+json;compatible-with=7 ' , $ request ['request ' ]['headers ' ]['Content-Type ' ]);
326+ $ this ->assertContains ('application/vnd.elasticsearch+json;compatible-with=7 ' , $ request ['request ' ]['headers ' ]['Accept ' ]);
327+ } else {
328+ $ this ->assertNotContains ('application/vnd.elasticsearch+json;compatible-with=7 ' , $ request ['request ' ]['headers ' ]['Content-Type ' ]);
329+ $ this ->assertNotContains ('application/vnd.elasticsearch+json;compatible-with=7 ' , $ request ['request ' ]['headers ' ]['Accept ' ]);
330+ }
331+ }
332+ }
333+
334+ public function testCompatibilityHeaderDefaultIsOff ()
335+ {
336+ $ client = ClientBuilder::create ()
337+ ->build ();
338+
339+ try {
340+ $ result = $ client ->info ();
341+ } catch (ElasticsearchException $ e ) {
342+ $ request = $ client ->transport ->getLastConnection ()->getLastRequestInfo ();
343+ $ this ->assertNotContains ('application/vnd.elasticsearch+json;compatible-with=7 ' , $ request ['request ' ]['headers ' ]['Content-Type ' ]);
344+ $ this ->assertNotContains ('application/vnd.elasticsearch+json;compatible-with=7 ' , $ request ['request ' ]['headers ' ]['Accept ' ]);
345+ }
346+ }
299347}
0 commit comments