<commit_before><?php

declare(strict_types=1);

namespace NewTwitchApi\Tests\Resources;

use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use NewTwitchApi\HelixGuzzleClient;
use NewTwitchApi\RequestGenerator;
use NewTwitchApi\Resources\UsersApi;
use PHPUnit\Framework\TestCase;

class UsersTest extends TestCase
{
    public function testGetUserByIdShouldReturnSuccessfulResponseWithUserData(): void
    {
        $users = new UsersApi($this->getHelixGuzzleClientWithMockUserResponse(), $this->getRequestGenerator());
        $response = $users->getUserById('TEST_APP_ACCESS_TOKEN', '<PASSWORD>');

        $this->assertEquals(200, $response->getStatusCode());
        $contents = json_decode($response->getBody()->getContents());
        $this->assertEquals('dallas', $contents->data[0]->login);
    }

    public function testGetUserByUsernameShouldReturnSuccessfulResponseWithUserData(): void
    {
        $users = new UsersApi($this->getHelixGuzzleClientWithMockUserResponse(), $this->getRequestGenerator());
        $response = $users->getUserByUsername('TEST_APP_ACCESS_TOKEN', '<PASSWORD>');

        $this->assertEquals(200, $response->getStatusCode());
        $contents = json_decode($response->getBody()->getContents());
        $this->assertEquals(44322889, $contents->data[0]->id);
    }

    private function getHelixGuzzleClientWithMockUserResponse(): HelixGuzzleClient
    {
        // Example response from https://dev.twitch.tv/docs/api/reference/#get-users
        $getUserReponseJson = <<<JSON
{
  "data": [{
    "id": "44322889",
    "login": "dallas",
    "display_name": "dallas",
    "type": "staff",
    "broadcaster_type": "",
    "description": "Just a gamer playing games and chatting. :)",
    "profile_image_url": "https://static-cdn.jtvnw.net/jtv_user_pictures/dallas-profile_image-1a2c906ee2c35f12-300x300.png",
    "offline_image_url": "https://static-cdn.jtvnw.net/jtv_user_pictures/dallas-channel_offline_image-1a2c906ee2c35f12-1920x1080.png",
    "view_count": 191836881,
    "email": "<EMAIL>"
  }]
}
JSON;

        $db_response = new Response(200, [], $getUserReponseJson);
        $mock = new MockHandler([$db_response, $db_response]);
        $handler = HandlerStack::create($mock);

        return new HelixGuzzleClient('123', ['handler' => $handler]);
    }

    private function getRequestGenerator(): RequestGenerator
    {
        return new RequestGenerator();
    }
}<commit_msg>Rename Client ID to TEST_CLIENT_ID<commit_after><?php

declare(strict_types=1);

namespace NewTwitchApi\Tests\Resources;

use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use NewTwitchApi\HelixGuzzleClient;
use NewTwitchApi\RequestGenerator;
use NewTwitchApi\Resources\UsersApi;
use PHPUnit\Framework\TestCase;

class UsersTest extends TestCase
{
    public function testGetUserByIdShouldReturnSuccessfulResponseWithUserData(): void
    {
        $users = new UsersApi($this->getHelixGuzzleClientWithMockUserResponse(), $this->getRequestGenerator());
        $response = $users->getUserById('TEST_APP_ACCESS_TOKEN', '44322889');

        $this->assertEquals(200, $response->getStatusCode());
        $contents = json_decode($response->getBody()->getContents());
        $this->assertEquals('dallas', $contents->data[0]->login);
    }

    public function testGetUserByUsernameShouldReturnSuccessfulResponseWithUserData(): void
    {
        $users = new UsersApi($this->getHelixGuzzleClientWithMockUserResponse(), $this->getRequestGenerator());
        $response = $users->getUserByUsername('TEST_APP_ACCESS_TOKEN', 'dallas');

        $this->assertEquals(200, $response->getStatusCode());
        $contents = json_decode($response->getBody()->getContents());
        $this->assertEquals(44322889, $contents->data[0]->id);
    }

    private function getHelixGuzzleClientWithMockUserResponse(): HelixGuzzleClient
    {
        // Example response from https://dev.twitch.tv/docs/api/reference/#get-users
        $getUserReponseJson = <<<JSON
{
  "data": [{
    "id": "44322889",
    "login": "dallas",
    "display_name": "dallas",
    "type": "staff",
    "broadcaster_type": "",
    "description": "Just a gamer playing games and chatting. :)",
    "profile_image_url": "https://static-cdn.jtvnw.net/jtv_user_pictures/dallas-profile_image-1a2c906ee2c35f12-300x300.png",
    "offline_image_url": "https://static-cdn.jtvnw.net/jtv_user_pictures/dallas-channel_offline_image-1a2c906ee2c35f12-1920x1080.png",
    "view_count": 191836881,
    "email": "<EMAIL>"
  }]
}
JSON;

        $db_response = new Response(200, [], $getUserReponseJson);
        $mock = new MockHandler([$db_response, $db_response]);
        $handler = HandlerStack::create($mock);

        return new HelixGuzzleClient('TEST_CLIENT_ID', ['handler' => $handler]);
    }

    private function getRequestGenerator(): RequestGenerator
    {
        return new RequestGenerator();
    }
}
{'fraction_non_alphanumeric': 0.1415929203539823, 'fraction_numerical': 0.031174577634754626, 'mean_word_length': 4.507198228128461, 'pattern_counts': {'":': 22, '<': 15, '<?xml version=': 0, '>': 49, 'https://': 6, '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': '1447289', 'n_tokens_mistral': 1660, 'n_tokens_neox': 1528, 'n_words': 234}