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 ;
16
+
17
+ use Elastic \Elasticsearch \Utility ;
18
+ use PHPUnit \Framework \TestCase ;
19
+
20
+ class UtilityTest extends TestCase
21
+ {
22
+ public function tearDown (): void
23
+ {
24
+ unset($ _SERVER [Utility::ENV_URL_PLUS_AS_SPACE ]);
25
+ unset($ _ENV [Utility::ENV_URL_PLUS_AS_SPACE ]);
26
+ putenv (Utility::ENV_URL_PLUS_AS_SPACE );
27
+ }
28
+
29
+ public function testGetEnvWithDollarServer ()
30
+ {
31
+ $ _SERVER [Utility::ENV_URL_PLUS_AS_SPACE ] = 'true ' ;
32
+ $ this ->assertEquals ('true ' , Utility::getEnv (Utility::ENV_URL_PLUS_AS_SPACE ));
33
+ }
34
+
35
+ public function testGetEnvWithDollarEnv ()
36
+ {
37
+ $ _ENV [Utility::ENV_URL_PLUS_AS_SPACE ] = 'true ' ;
38
+ $ this ->assertEquals ('true ' , Utility::getEnv (Utility::ENV_URL_PLUS_AS_SPACE ));
39
+ }
40
+
41
+ public function testGetEnvWithPutEnv ()
42
+ {
43
+ putenv (Utility::ENV_URL_PLUS_AS_SPACE . '=true ' );
44
+ $ this ->assertEquals ('true ' , Utility::getEnv (Utility::ENV_URL_PLUS_AS_SPACE ));
45
+ }
46
+
47
+ public function testUrlWithPlusAsDefault ()
48
+ {
49
+ $ url = Utility::urlencode ('bar baz ' );
50
+ $ this ->assertEquals ('bar+baz ' , $ url );
51
+ }
52
+
53
+ public function testUrlWithPlusWithDollarServer ()
54
+ {
55
+ $ _SERVER [Utility::ENV_URL_PLUS_AS_SPACE ] = 'true ' ;
56
+ $ url = Utility::urlencode ('bar baz ' );
57
+ $ this ->assertEquals ('bar+baz ' , $ url );
58
+ }
59
+
60
+ public function testUrlWithPlusWithDollarEnv ()
61
+ {
62
+ $ _ENV [Utility::ENV_URL_PLUS_AS_SPACE ] = 'true ' ;
63
+ $ url = Utility::urlencode ('bar baz ' );
64
+ $ this ->assertEquals ('bar+baz ' , $ url );
65
+ }
66
+
67
+ public function testUrlWithPlusWithPutEnv ()
68
+ {
69
+ putenv (Utility::ENV_URL_PLUS_AS_SPACE . '=true ' );
70
+ $ url = Utility::urlencode ('bar baz ' );
71
+ $ this ->assertEquals ('bar+baz ' , $ url );
72
+ }
73
+
74
+ public function testUrlWith2BWithDollarServer ()
75
+ {
76
+ $ _SERVER [Utility::ENV_URL_PLUS_AS_SPACE ] = 'false ' ;
77
+ $ url = Utility::urlencode ('bar baz ' );
78
+ $ this ->assertEquals ('bar%20baz ' , $ url );
79
+ }
80
+
81
+ public function testUrlWith2BWithDollarEnv ()
82
+ {
83
+ $ _ENV [Utility::ENV_URL_PLUS_AS_SPACE ] = 'false ' ;
84
+ $ url = Utility::urlencode ('bar baz ' );
85
+ $ this ->assertEquals ('bar%20baz ' , $ url );
86
+ }
87
+
88
+ public function testUrlWith2BWithPutEnv ()
89
+ {
90
+ putenv (Utility::ENV_URL_PLUS_AS_SPACE . '=false ' );
91
+ $ url = Utility::urlencode ('bar baz ' );
92
+ $ this ->assertEquals ('bar%20baz ' , $ url );
93
+ }
94
+ }
0 commit comments