<commit_before><?php

namespace Elastica\Test\Transport;

use Elastica\Client;
use Elastica\Test\Base as BaseTest;

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 array[]
     */
    public function getConfig()
    {
        return array(
            array(
                array('transport' => 'Http'),
                'GET'
            ),
            array(
                array('transport' => array('type' => 'Http', 'postWithRequestBody' => false)),
                'GET'
            ),
            array(
                array('transport' => array('type' => 'Http', 'postWithRequestBody' => true)),
                'POST'
            ),
        );
    }

    /**
     * @dataProvider getConfig
     */
    public function testDynamicHttpMethodBasedOnConfigParameter(array $config, $httpMethod)
    {
        $client = new Client($config);

        $index = $client->getIndex('elastica_test1');
        $index->create(array(), true);
        $index->refresh();

        $resultSet = $index->search('test');

        $info = $resultSet->getResponse()->getTransferInfo();
        $this->assertStringStartsWith($httpMethod, $info['request_header']);
    }

    /**
     * @dataProvider getConfig<commit_msg>Don't delete the index as it causes some issues with the cluster not being ready for the query<commit_after><?php

namespace Elastica\Test\Transport;

use Elastica\Client;
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 array[]
     */
    public function getConfig()
    {
        return array(
            array(
                array('transport' => 'Http'),
                'GET'
            ),
            array(
                array('transport' => array('type' => 'Http', 'postWithRequestBody' => false)),
                'GET'
            ),
            array(
                array('transport' => array('type' => 'Http', 'postWithRequestBody' => true)),
                'POST'
            ),
        );
    }

    /**
     * @dataProvider getConfig
     */
    public function testDynamicHttpMethodBasedOnConfigParameter(array $config, $httpMethod)
    {
        $client = new Client($config);

        $index = $client->getIndex('dynamic_http_method_test');

        try {
            $index->create();
        } catch (ResponseException $e) {
            // ignore
        }

        $resultSet = $index->search('test');

        $info = $resultSet->getResponse()->getTransferInfo();
        $this->assertStringStartsWith($httpMethod, $info['request_header']);
    }

    /**
     * @dataProvider getConfig
{'fraction_non_alphanumeric': 0.13341382432840326, 'fraction_numerical': 0.00030184123151222455, 'mean_word_length': 1.9223985890652557, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '925360', 'n_tokens_mistral': 898, 'n_tokens_neox': 874, 'n_words': 205}