Skip to content

Commit b2456bc

Browse files
committed
Make proxy url also dynamic
1 parent 3c8c9e7 commit b2456bc

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

test/lib/Elastica/Test/Base.php

+8
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ protected function _getHost()
3232
return getenv('ES_HOST') ?: 'localhost';
3333
}
3434

35+
/**
36+
* @return string Proxy url string
37+
*/
38+
protected function _getProxyUrl()
39+
{
40+
return "http://127.0.0.1:12345";
41+
}
42+
3543
/**
3644
* @param string $name Index name
3745
* @param bool $delete Delete index if it exists

test/lib/Elastica/Test/Transport/GuzzleTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function testDynamicHttpMethodOnlyAffectsRequestsWithBody(array $config,
8282

8383
public function testWithEnvironmentalProxy()
8484
{
85-
putenv('http_proxy=http://127.0.0.1:12345/');
85+
putenv('http_proxy=' . $this->_getProxyUrl());
8686

8787
$client = new \Elastica\Client(array('transport' => 'Guzzle', 'persistent' => false));
8888
$transferInfo = $client->request('/_nodes')->getTransferInfo();
@@ -97,7 +97,7 @@ public function testWithEnvironmentalProxy()
9797

9898
public function testWithEnabledEnvironmentalProxy()
9999
{
100-
putenv('http_proxy=http://127.0.0.1:12346/');
100+
putenv('http_proxy=' . $this->_getProxyUrl());
101101

102102
$client = new \Elastica\Client(array('transport' => 'Guzzle', 'persistent' => false));
103103
$transferInfo = $client->request('/_nodes')->getTransferInfo();
@@ -114,7 +114,7 @@ public function testWithEnabledEnvironmentalProxy()
114114
public function testWithProxy()
115115
{
116116
$client = new \Elastica\Client(array('transport' => 'Guzzle', 'persistent' => false));
117-
$client->getConnection()->setProxy('http://127.0.0.1:12345');
117+
$client->getConnection()->setProxy($this->_getProxyUrl());
118118

119119
$transferInfo = $client->request('/_nodes')->getTransferInfo();
120120
$this->assertEquals(200, $transferInfo['http_code']);

test/lib/Elastica/Test/Transport/HttpTest.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function testDynamicHttpMethodOnlyAffectsRequestsWithBody(array $config,
8080

8181
public function testCurlNobodyOptionIsResetAfterHeadRequest()
8282
{
83-
$client = new \Elastica\Client();
83+
$client = $this->_getClient();
8484
$index = $client->getIndex('curl_test');
8585
$index->create(array(), true);
8686
$this->_waitForAllocation($index);
@@ -106,7 +106,7 @@ public function testCurlNobodyOptionIsResetAfterHeadRequest()
106106

107107
public function testUnicodeData()
108108
{
109-
$client = new \Elastica\Client();
109+
$client = $this->_getClient();
110110
$index = $client->getIndex('curl_test');
111111
$index->create(array(), true);
112112
$this->_waitForAllocation($index);
@@ -138,9 +138,9 @@ public function testUnicodeData()
138138

139139
public function testWithEnvironmentalProxy()
140140
{
141-
putenv('http_proxy=http://127.0.0.1:12345/');
141+
putenv('http_proxy=' . $this->_getProxyUrl());
142142

143-
$client = new \Elastica\Client();
143+
$client = $this->_getClient();
144144
$transferInfo = $client->request('/_nodes')->getTransferInfo();
145145
$this->assertEquals(200, $transferInfo['http_code']);
146146

@@ -153,14 +153,14 @@ public function testWithEnvironmentalProxy()
153153

154154
public function testWithEnabledEnvironmentalProxy()
155155
{
156-
putenv('http_proxy=http://127.0.0.1:12346/');
156+
putenv('http_proxy=' . $this->_getProxyUrl());
157157

158-
$client = new \Elastica\Client();
158+
$client = $this->_getClient();
159159

160160
$transferInfo = $client->request('/_nodes')->getTransferInfo();
161161
$this->assertEquals(403, $transferInfo['http_code']);
162162

163-
$client = new \Elastica\Client();
163+
$client = $this->_getClient();
164164
$client->getConnection()->setProxy('');
165165
$transferInfo = $client->request('/_nodes')->getTransferInfo();
166166
$this->assertEquals(200, $transferInfo['http_code']);
@@ -170,16 +170,16 @@ public function testWithEnabledEnvironmentalProxy()
170170

171171
public function testWithProxy()
172172
{
173-
$client = new \Elastica\Client();
174-
$client->getConnection()->setProxy('http://127.0.0.1:12345');
173+
$client = $this->_getClient();
174+
$client->getConnection()->setProxy($this->_getProxyUrl());
175175

176176
$transferInfo = $client->request('/_nodes')->getTransferInfo();
177177
$this->assertEquals(200, $transferInfo['http_code']);
178178
}
179179

180180
public function testWithoutProxy()
181181
{
182-
$client = new \Elastica\Client();
182+
$client = $this->_getClient();
183183
$client->getConnection()->setProxy('');
184184

185185
$transferInfo = $client->request('/_nodes')->getTransferInfo();

0 commit comments

Comments
 (0)