<commit_before><?php

namespace Klaviyo\Tests;

use Http\Factory\Guzzle\RequestFactory;
use Http\Factory\Guzzle\StreamFactory;
use Klaviyo\KlaviyoApi;
use Psr\Http\Message\ResponseInterface;

class KlaviyoApiTest extends KlaviyoTestCase
{

    public function testCanGetApiEndpoint()
    {
        $this->assertSame($this->endPoint, KlaviyoApi::$endPoint, 'The API end point should be available.');
    }

    public function testRequestWithEndPointAndApiKey()
    {
        $container = [];
        $client = $this->getClient($container);

        $api = new KlaviyoApi($client, new RequestFactory(), new StreamFactory(), 'thisisakey');
        $response = $api->request('GET', 'api/v1');

        $request = $container[0]['request'];
        $this->assertSame('GET', $request->getMethod(), 'The request should had been GET.');
        $this->assertSame($this->endPoint . '/api/v1?api_key=thisisakey', (string) $request->getUri(), 'The request URI should include the resource and api key.');
        $this->assertInstanceOf(ResponseInterface::class, $response, 'The response should had been a Response object.');
    }

    public function testOptions()
    {
        $options = ['records_per_page' => 20];
        $api = $this->getApi('thisisakey', $options);
        $this->assertSame(20, $api->getOption('records_per_page'));
        $this->assertSame($options, $api->getAllOptions());
        $api->setOption('records_per_page', 1)->setOption('records_per_page', 5);
        $this->assertSame(5, $api->getOption('records_per_page'));
    }

    public function testDefaultOptions()
    {
        $api = $this->getApi('thisisakey');
        $this->assertSame(50, $api->getOption('records_per_page'));
    }
}<commit_msg>Add test to verify correct content-type header on none GET requests<commit_after><?php

namespace Klaviyo\Tests;

use Http\Factory\Guzzle\RequestFactory;
use Http\Factory\Guzzle\StreamFactory;
use Klaviyo\KlaviyoApi;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

class KlaviyoApiTest extends KlaviyoTestCase
{

    public function testCanGetApiEndpoint()
    {
        $this->assertSame($this->endPoint, KlaviyoApi::$endPoint, 'The API end point should be available.');
    }

    public function testRequestWithEndPointAndApiKey()
    {
        $container = [];
        $client = $this->getClient($container);

        $api = new KlaviyoApi($client, new RequestFactory(), new StreamFactory(), 'thisisakey');
        $response = $api->request('GET', 'api/v1');

        $request = $container[0]['request'];
        $this->assertSame('GET', $request->getMethod(), 'The request should had been GET.');
        $this->assertSame($this->endPoint . '/api/v1?api_key=thisisakey', (string) $request->getUri(), 'The request URI should include the resource and api key.');
        $this->assertInstanceOf(ResponseInterface::class, $response, 'The response should had been a Response object.');
    }

    public function testRequestWithPostAndContentType()
    {
        $container = [];
        $client = $this->getClient($container);

        $api = new KlaviyoApi($client, new RequestFactory(), new StreamFactory(), 'thisisakey');
        $response = $api->request('POST', 'api/v1');

        /** @var RequestInterface $request */
        $request = $container[0]['request'];
        $this->assertSame('POST', $request->getMethod(), 'The request should had been GET.');
        $this->assertSame('application/x-www-form-urlencoded', $request->getHeaderLine('Content-Type'), 'The request should have had content-type: application/x-www-form-urlencoded.');
        $this->assertSame('api_key=thisisakey', (string) $request->getBody(), 'The request body should include the api key.');
        $this->assertInstanceOf(ResponseInterface::class, $response, 'The response should had been a Response object.');
    }

    public function testOptions()
    {
        $options = ['records_per_page' => 20];
        $api = $this->getApi('thisisakey', $options);
        $this->assertSame(20, $api->getOption('records_per_page'));
        $this->assertSame($options, $api->getAllOptions());
        $api->setOption('records_per_page', 1)->setOption('records_per_page', 5);
        $this->assertSame(5, $api->getOption('records_per_page'));
    }

    public function testDefaultOptions()
    {
        $api = $this->getApi('thisisakey');
        $this->assertSame(50, $api->getOption('records_per_page'));
    }
}
{'fraction_non_alphanumeric': 0.15607455647877835, 'fraction_numerical': 0.005838760386256457, 'mean_word_length': 3.8308026030368763, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 58, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7025163', 'n_tokens_mistral': 1335, 'n_tokens_neox': 1305, 'n_words': 278}