diff options
Diffstat (limited to 'vendor/ruflin/elastica/test/lib/Elastica/Test/Transport/HttpTest.php')
-rw-r--r-- | vendor/ruflin/elastica/test/lib/Elastica/Test/Transport/HttpTest.php | 103 |
1 files changed, 61 insertions, 42 deletions
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Transport/HttpTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Transport/HttpTest.php index 88c93bea..53ee105f 100644 --- a/vendor/ruflin/elastica/test/lib/Elastica/Test/Transport/HttpTest.php +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Transport/HttpTest.php @@ -1,29 +1,15 @@ <?php - namespace Elastica\Test\Transport; -use Elastica\Client; use Elastica\Document; use Elastica\Query; use Elastica\ResultSet; use Elastica\Test\Base as BaseTest; -use Elastica\Exception\ResponseException; class HttpTest extends BaseTest { - public function setUp() - { - if (defined('DEBUG') && !DEBUG) { - $this->markTestSkipped('The DEBUG constant must be set to true for this test to run'); - } - - if (!defined('DEBUG')) { - define('DEBUG', true); - } - } - /** - * Return transport configuration and the expected HTTP method + * Return transport configuration and the expected HTTP method. * * @return array[] */ @@ -31,30 +17,31 @@ class HttpTest extends BaseTest { return array( array( - array('transport' => 'Http'), - 'GET' + array('transport' => 'Http', 'curl' => array(CURLINFO_HEADER_OUT => true)), + 'GET', ), array( - array('transport' => array('type' => 'Http', 'postWithRequestBody' => false)), - 'GET' + array('transport' => array('type' => 'Http', 'postWithRequestBody' => false, 'curl' => array(CURLINFO_HEADER_OUT => true))), + 'GET', ), array( - array('transport' => array('type' => 'Http', 'postWithRequestBody' => true)), - 'POST' + array('transport' => array('type' => 'Http', 'postWithRequestBody' => true, 'curl' => array(CURLINFO_HEADER_OUT => true))), + 'POST', ), ); } /** + * @group functional * @dataProvider getConfig */ public function testDynamicHttpMethodBasedOnConfigParameter(array $config, $httpMethod) { - $client = new Client($config); + $client = $this->_getClient($config); $index = $client->getIndex('dynamic_http_method_test'); - $index->create(array(), true); + $this->_waitForAllocation($index); $type = $index->getType('test'); $type->addDocument(new Document(1, array('test' => 'test'))); @@ -68,23 +55,29 @@ class HttpTest extends BaseTest } /** + * @group functional * @dataProvider getConfig */ public function testDynamicHttpMethodOnlyAffectsRequestsWithBody(array $config, $httpMethod) { - $client = new Client($config); + $client = $this->_getClient($config); $status = $client->getStatus(); $info = $status->getResponse()->getTransferInfo(); $this->assertStringStartsWith('GET', $info['request_header']); } + /** + * @group functional + */ public function testCurlNobodyOptionIsResetAfterHeadRequest() { - $client = new \Elastica\Client(); + $client = $this->_getClient(); $index = $client->getIndex('curl_test'); - $type = $index->getType('item'); + $index->create(array(), true); + $this->_waitForAllocation($index); + $type = $index->getType('item'); // Force HEAD request to set CURLOPT_NOBODY = true $index->exists(); @@ -103,10 +96,16 @@ class HttpTest extends BaseTest $this->assertEquals($id, $doc->getId()); } + /** + * @group functional + */ public function testUnicodeData() { - $client = new \Elastica\Client(); + $client = $this->_getClient(); $index = $client->getIndex('curl_test'); + $index->create(array(), true); + $this->_waitForAllocation($index); + $type = $index->getType('item'); // Force HEAD request to set CURLOPT_NOBODY = true @@ -132,11 +131,14 @@ class HttpTest extends BaseTest $this->assertEquals($id, $doc->getId()); } + /** + * @group functional + */ 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']); @@ -147,48 +149,56 @@ class HttpTest extends BaseTest putenv('http_proxy='); } + /** + * @group functional + */ public function testWithEnabledEnvironmentalProxy() { - putenv('http_proxy=http://127.0.0.1:12346/'); - - $client = new \Elastica\Client(); - + putenv('http_proxy='.$this->_getProxyUrl403().'/'); + $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']); - putenv('http_proxy='); } + /** + * @group functional + */ 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']); } + /** + * @group functional + */ public function testWithoutProxy() { - $client = new \Elastica\Client(); + $client = $this->_getClient(); $client->getConnection()->setProxy(''); $transferInfo = $client->request('/_nodes')->getTransferInfo(); $this->assertEquals(200, $transferInfo['http_code']); } + /** + * @group functional + */ public function testBodyReuse() { - $client = new Client(); + $client = $this->_getClient(); $index = $client->getIndex('elastica_body_reuse_test'); - $index->create(array(), true); + $this->_waitForAllocation($index); $type = $index->getType('test'); $type->addDocument(new Document(1, array('test' => 'test'))); @@ -211,12 +221,16 @@ class HttpTest extends BaseTest $this->assertEquals(1, $resultSet->getTotalHits()); } + /** + * @group functional + */ public function testPostWith0Body() { - $client = new Client(); + $client = $this->_getClient(); $index = $client->getIndex('elastica_0_body'); $index->create(array(), true); + $this->_waitForAllocation($index); $index->refresh(); $tokens = $index->analyze('0'); @@ -224,4 +238,9 @@ class HttpTest extends BaseTest $this->assertNotEmpty($tokens); } + protected function tearDown() + { + parent::tearDown(); + putenv('http_proxy='); + } } |