Skip to content

Commit

Permalink
Make proxy url also dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
ruflin committed May 16, 2015
1 parent 3c8c9e7 commit b2456bc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
8 changes: 8 additions & 0 deletions test/lib/Elastica/Test/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ protected function _getHost()
return getenv('ES_HOST') ?: 'localhost';
}

/**
* @return string Proxy url string
*/
protected function _getProxyUrl()
{
return "http://127.0.0.1:12345";
}

/**
* @param string $name Index name
* @param bool $delete Delete index if it exists
Expand Down
6 changes: 3 additions & 3 deletions test/lib/Elastica/Test/Transport/GuzzleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function testDynamicHttpMethodOnlyAffectsRequestsWithBody(array $config,

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

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

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

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

$transferInfo = $client->request('/_nodes')->getTransferInfo();
$this->assertEquals(200, $transferInfo['http_code']);
Expand Down
20 changes: 10 additions & 10 deletions test/lib/Elastica/Test/Transport/HttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function testDynamicHttpMethodOnlyAffectsRequestsWithBody(array $config,

public function testCurlNobodyOptionIsResetAfterHeadRequest()
{
$client = new \Elastica\Client();
$client = $this->_getClient();
$index = $client->getIndex('curl_test');
$index->create(array(), true);
$this->_waitForAllocation($index);
Expand All @@ -106,7 +106,7 @@ public function testCurlNobodyOptionIsResetAfterHeadRequest()

public function testUnicodeData()
{
$client = new \Elastica\Client();
$client = $this->_getClient();
$index = $client->getIndex('curl_test');
$index->create(array(), true);
$this->_waitForAllocation($index);
Expand Down Expand Up @@ -138,9 +138,9 @@ public function testUnicodeData()

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

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

Expand All @@ -153,14 +153,14 @@ public function testWithEnvironmentalProxy()

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

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

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

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

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

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

public function testWithoutProxy()
{
$client = new \Elastica\Client();
$client = $this->_getClient();
$client->getConnection()->setProxy('');

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

0 comments on commit b2456bc

Please sign in to comment.