<commit_before><?php

namespace Florence\Test;

use Florence\Emoji;
use Florence\Config;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;

class EmojiRestApiTest extends \PHPUnit_Framework_TestCase
{
    protected $emoji;
    protected $client;
    protected $url;
    protected $token;
    protected $testId;

    public function setUp ()
    {
        Config::loadenv();

        $this->token = getenv('TEST_TOKEN');
        $this->username = getenv('TEST_USERNAME');
        $this->password = getenv('<PASSWORD>');
        $this->new_user = getenv('NEW_USER');
        $this->testId = 3;
        $this->emoji = new Emoji();
        $this->client = new Client();
        $this->url = "http://emojis4devs.herokuapp.com";
        // $this->url = "http://localhost:8080";
    }

    /**
    * test register with registration params
    */
    public function testRegisterWithParams()
    {
        $data = [
            'username' => $this->new_user,
            'password' => $<PASSWORD>
        ];
        $request = $this->client->request('POST', $this->url.'/register', ['form_params' => $data]);

        $this->assertInternalType('object' , $request);
        $this->assertEquals('200', $request->getStatusCode());
    }

    /**
    * @expectedException GuzzleHttp\Exception\ClientException
    */
    public function testRegisterWithoutParams()
    {
        $request = $this->client->request('POST', $this->url.'/register');

        $this->assertInternalType('object' , $request);
        $this->assertEquals('200', $request->getStatusCode());
    }

    /**
    * @expectedException GuzzleHttp\Exception\ClientException
    */
    public function testLoginWithoutCredentials()
    {
        $request = $this->client->request('POST', $this->url.'/auth/login');

        $this->assertInternalType('object' , $request);
        $this->assertEquals('200', $request->getStatusCode());
    }

    /**
    * @expectedException GuzzleHttp\Exception\ClientException
    */
    public function testInvalidEndpoint()
    {
        $request = $this->client->request('GET', $this->url.'/auth/emojis');

        $this->assertInternalType('object' , $request);
        $this->assertEquals('200', $request->getStatusCode());
    }

    /**
    * Test for unprotected Get Routes (Index and getAll)
    */
    public function testUnprotectedGetRoutes()
    {
        $index = $this->client->request('GET', $this->url);
        $getAll = $this->client->request('GET', $this->url);

        $_index = $index->getHeader('content-type')[0];
        $_getAll = $getAll->getHeader('content-type')[0];

        $this->assertEquals('200', $index->getStatusCode());
        $this->assertEquals('200', $getAll->getStatusCode());
        $this->assertInternalType('object', $index->getBody());
        $this->assertInternalType('object', $index->getBody());
        $this->assertEquals('text/html;charset=UTF-8', $_index);
        $this->assertEquals('text/html;charset=UTF-8', $_getAll);
    }

    /**
    * @expectedException GuzzleHttp\Exception\ClientException
    */
    public function testCreateWithAuthorizationNotSet ()
    {
        $data = [
            'name' => 'TestEmojiName',
            'char' => '🎃',
            'keywords' => "apple, friut, mac",
            'category' => 'fruit'
        ];

        $request = $this->client->request('POST', $this->url.'/emojis', ['form_params' => $data]);
    }

    /**<commit_msg>Test create emoji without params set<commit_after><?php

namespace Florence\Test;

use Florence\Emoji;
use Florence\Config;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;

class EmojiRestApiTest extends \PHPUnit_Framework_TestCase
{
    protected $emoji;
    protected $client;
    protected $url;
    protected $token;
    protected $testId;

    public function setUp ()
    {
        Config::loadenv();

        $this->token = getenv('TEST_TOKEN');
        $this->username = getenv('TEST_USERNAME');
        $this->password = getenv('<PASSWORD>_PASSWORD');
        $this->new_user = getenv('NEW_USER');
        $this->testId = 3;
        $this->emoji = new Emoji();
        $this->client = new Client();
        $this->url = "http://emojis4devs.herokuapp.com";
        // $this->url = "http://localhost:8080";
    }

    /**
    * test register with registration params
    */
    public function testRegisterWithParams()
    {
        $data = [
            'username' => $this->new_user,
            'password' => $<PASSWORD>
        ];
        $request = $this->client->request('POST', $this->url.'/register', ['form_params' => $data]);

        $this->assertInternalType('object' , $request);
        $this->assertEquals('200', $request->getStatusCode());
    }

    /**
    * @expectedException GuzzleHttp\Exception\ClientException
    */
    public function testRegisterWithoutParams()
    {
        $request = $this->client->request('POST', $this->url.'/register');

        $this->assertInternalType('object' , $request);
        $this->assertEquals('200', $request->getStatusCode());
    }

    /**
    * @expectedException GuzzleHttp\Exception\ClientException
    */
    public function testLoginWithoutCredentials()
    {
        $request = $this->client->request('POST', $this->url.'/auth/login');

        $this->assertInternalType('object' , $request);
        $this->assertEquals('200', $request->getStatusCode());
    }

    /**
    * @expectedException GuzzleHttp\Exception\ClientException
    */
    public function testInvalidEndpoint()
    {
        $request = $this->client->request('GET', $this->url.'/auth/emojis');

        $this->assertInternalType('object' , $request);
        $this->assertEquals('200', $request->getStatusCode());
    }

    /**
    * Test for unprotected Get Routes (Index and getAll)
    */
    public function testUnprotectedGetRoutes()
    {
        $index = $this->client->request('GET', $this->url);
        $getAll = $this->client->request('GET', $this->url);

        $_index = $index->getHeader('content-type')[0];
        $_getAll = $getAll->getHeader('content-type')[0];

        $this->assertEquals('200', $index->getStatusCode());
        $this->assertEquals('200', $getAll->getStatusCode());
        $this->assertInternalType('object', $index->getBody());
        $this->assertInternalType('object', $index->getBody());
        $this->assertEquals('text/html;charset=UTF-8', $_index);
        $this->assertEquals('text/html;charset=UTF-8', $_getAll);
    }

    /**
    * @expectedException GuzzleHttp\Exception\ClientException
    */
    public function testCreateWithAuthorizationNotSet ()
    {
        $data = [
            'name' => 'TestEmojiName',
            'char' => '🎃',
            'keywords' => "apple, friut, mac",
            'category' => 'fruit'
        ];

        $request = $this->client->request('POST', $this->url.'/emojis', ['form_params' => $data]);
    }

    /**
    * @expectedException GuzzleHttp\Exception\ClientException
    */
    public function testCreateWithoutEmojiParams ()
    {
        $request = $this->client->request('POST', $this->url.'/emojis',[ 'headers' =>
            ['Authorization'=> $this->token]]);

        $this->assertEquals('401', $request->getStatusCode());
    }

    /**
{'fraction_non_alphanumeric': 0.1763325048329191, 'fraction_numerical': 0.008146920740127036, 'mean_word_length': 2.7901622187336472, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 141, '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': '4793371', 'n_tokens_mistral': 2169, 'n_tokens_neox': 2105, 'n_words': 340}