1
+ <?php
2
+ /**
3
+ * Elasticsearch PHP Client
4
+ *
5
+ * @link https://github.com/elastic/elasticsearch-php
6
+ * @copyright Copyright (c) Elasticsearch B.V (https://www.elastic.co)
7
+ * @license https://opensource.org/licenses/MIT MIT License
8
+ *
9
+ * Licensed to Elasticsearch B.V under one or more agreements.
10
+ * Elasticsearch B.V licenses this file to you under the MIT License.
11
+ * See the LICENSE file in the project root for more information.
12
+ */
13
+ declare (strict_types = 1 );
14
+
15
+ namespace Elastic \Elasticsearch \Tests \Integration ;
16
+
17
+ use Elastic \Elasticsearch \ClientBuilder ;
18
+ use Http \Promise \Promise ;
19
+ use PHPUnit \Framework \TestCase ;
20
+ use Symfony \Component \HttpClient \Psr18Client ;
21
+ use Symfony \Component \HttpClient \HttplugClient ;
22
+
23
+ /**
24
+ * @group cloud
25
+ */
26
+ class ElasticCloudTest extends TestCase
27
+ {
28
+ const CLOUD_ID = 'ELASTIC_CLOUD_ID ' ;
29
+ const API_KEY = 'ELASTIC_API_KEY ' ;
30
+
31
+ protected ClientBuilder $ clientBuilder ;
32
+
33
+ public function setUp (): void
34
+ {
35
+ if (!getenv (self ::CLOUD_ID ) && !getenv (self ::API_KEY )) {
36
+ $ this ->markTestSkipped (sprintf (
37
+ "I cannot execute the Elastic Cloud test without the env variables %s and %s " ,
38
+ self ::CLOUD_ID ,
39
+ self ::API_KEY
40
+ ));
41
+ }
42
+ $ this ->clientBuilder = ClientBuilder::create ()
43
+ ->setElasticCloudId (getenv (self ::CLOUD_ID ))
44
+ ->setApiKey (getenv (self ::API_KEY ));
45
+ }
46
+
47
+ public function testInfoWithAsyncSymfonyHttplugClient ()
48
+ {
49
+ $ symfonyClient = new HttplugClient ();
50
+
51
+ $ client = $ this ->clientBuilder ->setAsyncHttpClient ($ symfonyClient )
52
+ ->build ();
53
+
54
+ $ client ->setAsync (true );
55
+
56
+ $ promise = $ client ->info ();
57
+ $ this ->assertInstanceOf (Promise::class, $ promise );
58
+ $ response = $ promise ->wait ();
59
+
60
+ $ this ->assertEquals (200 , $ response ->getStatusCode ());
61
+ $ this ->assertNotEmpty ($ response ['name ' ]);
62
+ $ this ->assertNotEmpty ($ response ['version ' ]['number ' ]);
63
+ }
64
+
65
+ public function testInfoWithSymfonyHttpPsr18Client ()
66
+ {
67
+ $ symfonyClient = new Psr18Client ();
68
+
69
+ $ client = $ this ->clientBuilder ->setHttpClient ($ symfonyClient )
70
+ ->build ();
71
+
72
+ $ response = $ client ->info ();
73
+ $ this ->assertEquals (200 , $ response ->getStatusCode ());
74
+ $ this ->assertNotEmpty ($ response ['name ' ]);
75
+ $ this ->assertNotEmpty ($ response ['version ' ]['number ' ]);
76
+ }
77
+ }
0 commit comments