<commit_before><?php

/*
 * This file is part of the Spira framework.
 *
 * @link https://github.com/spira/spira
 *
 * For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
 */

use Illuminate\Support\Facades\DB;

class TestCase extends Laravel\Lumen\Testing\TestCase
{
    use AssertionsTrait, HelpersTrait, ModelFactoryTrait;

    /**
     * Setup the test environment.
     *
     * @return void
     */
    public function setUp()
    {
        parent::setUp();

        $this->bootTraits();

        DB::connection()->beginTransaction(); //start a new transaction
    }

    public function tearDown()
    {
        DB::connection()->rollBack(); //rollback the transaction so the test case can be rerun without duplicate key exceptions
        DB::connection()->setPdo(null); //close the pdo connection to `avoid too many connections` errors
        parent::tearDown();
    }

    /**
     * Allow traits to have custom initialization built in.
     *
     * @return void
     */
    protected function bootTraits()
    {
        foreach (get_declared_traits() as $trait) {
            if (method_exists($this, 'boot'.$trait)) {
                $this->{'boot'.$trait}();
            }
        }
    }

    /**
     * Creates the application.
     *
     * @return \Laravel\Lumen\Application
     */
    public function createApplication()
    {
        return require __DIR__.'/../bootstrap/app.php';
    }

    /**
     * Transform headers array to array of $_SERVER vars with HTTP_* format.
     *
     * @param  array $headers
     *
     * @return array
     */
    protected function transformHeadersToServerVars(array $headers)
    {
        $server = [];

        foreach ($headers as $name => $value) {
            $name = strtr(strtoupper($name), '-', '_');
            $server[$name] = $value; //set the server header to SNAKE_CASE

            if (! starts_with($name, 'HTTP_')) {
                $name = 'HTTP_'.$name;
                $server[$name] = $value; //add the HTTP_* key
            }
        }

        return $server;
    }

    /**
     * Visit the given URI with a [$method] request with content type of application/json.
     *
     * @param $method
     * @param  string $uri
     * @param  array $data
     * @param  array $headers
     * @return $this
     */
    public function requestJson($method, $uri, array $data = [], array $headers = [])
    {
        $content = json_encode($data);

        $headers = $this->addJsonHeaders($headers, $content);
        $server = $this->transformHeadersToServerVars($headers);

        $this->call($method, $uri, [], [], [], $server, $content);

        return $this;
    }

    /**
     * @param array $headers
     * @param $content
     * @return array
     */
    protected function addJsonHeaders(array $headers, $content)
    {
        $headers['Content-Type'] = 'application/json';
        $headers['Content-Length'] = mb_strlen($content, '8bit');
        if (! isset($headers['Accept'])) {
            $headers['Accept'] = 'application/json';

            return $headers;
        }

        return $headers;
    }

    /**
     * Visit the given URI with a GET request with content type of application/json.
     *
     * @param  string  $uri
     * @param  array  $data
     * @param  array  $headers
     * @return $this
     */
    public function getJson($uri, array $headers = [])
    {
        return $this->requestJson('GET', $uri, [], $headers);
    }

    /**
     * Visit the given URI with a POST request with content type of application/json.
     *
     * @param  string  $uri
     * @param  array  $data
     * @param  array  $headers
     * @return $this
     */
    public function postJson($uri, array $data = [], array $headers = [])
    {
        return $this->requestJson('POST', $uri, $data, $headers);
    }
<commit_msg>Adding put routes for Localizations, implementing tests (incomplete).<commit_after><?php

/*
 * This file is part of the Spira framework.
 *
 * @link https://github.com/spira/spira
 *
 * For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
 */

use Illuminate\Support\Facades\DB;

class TestCase extends Laravel\Lumen\Testing\TestCase
{
    use AssertionsTrait, HelpersTrait, ModelFactoryTrait;

    /**
     * Setup the test environment.
     *
     * @return void
     */
    public function setUp()
    {
        parent::setUp();

        $this->bootTraits();

        DB::connection()->beginTransaction(); //start a new transaction
    }

    public function tearDown()
    {
        DB::connection()->rollBack(); //rollback the transaction so the test case can be rerun without duplicate key exceptions
        DB::connection()->setPdo(null); //close the pdo connection to `avoid too many connections` errors
        parent::tearDown();
    }

    /**
     * Allow traits to have custom initialization built in.
     *
     * @return void
     */
    protected function bootTraits()
    {
        foreach (get_declared_traits() as $trait) {
            if (method_exists($this, 'boot'.$trait)) {
                $this->{'boot'.$trait}();
            }
        }
    }

    /**
     * Creates the application.
     *
     * @return \Laravel\Lumen\Application
     */
    public function createApplication()
    {
        return require __DIR__.'/../bootstrap/app.php';
    }

    /**
     * Transform headers array to array of $_SERVER vars with HTTP_* format.
     *
     * @param  array $headers
     *
     * @return array
     */
    protected function transformHeadersToServerVars(array $headers)
    {
        $server = [];

        foreach ($headers as $name => $value) {
            $name = strtr(strtoupper($name), '-', '_');
            $server[$name] = $value; //set the server header to SNAKE_CASE

            if (! starts_with($name, 'HTTP_')) {
                $name = 'HTTP_'.$name;
                $server[$name] = $value; //add the HTTP_* key
            }
        }

        return $server;
    }

    /**
     * Visit the given URI with a [$method] request with content type of application/json.
     *
     * @param $method
     * @param  string $uri
     * @param  array $data
     * @param  array $headers
     * @return $this
     */
    public function requestJson($method, $uri, array $data = [], array $headers = [])
    {
        $content = json_encode($data);

        $headers = $this->addJsonHeaders($headers, $content);
        $server = $this->transformHeadersToServerVars($headers);

        $this->call($method, $uri, [], [], [], $server, $content);

        return $this;
    }

    /**
     * @param array $headers
     * @param $content
     * @return array
     */
    protected function addJsonHeaders(array $headers, $content)
    {
        $headers['Content-Type'] = 'application/json';
        $headers['Content-Length'] = mb_strlen($content, '8bit');
        if (! isset($headers['Accept'])) {
            $headers['Accept'] = 'application/json';

            return $headers;
        }

        return $headers;
    }

    /**
     * Visit the given URI with a PUT request with content type of text/plain.
     *
     * @param  string  $uri
     * @param  array  $data
     * @param  array  $headers
     * @return $this
     */
    public function putText($uri, $data, array $headers = [])
    {
        $server = $this->transformHeadersToServerVars(array_merge([
            'Content-Type' => 'text/plain'
        ], $headers));

        $this->call('PUT', $uri, [], [], [], $server, $data);

        return $this;
    }

    /**
     * Visit the given URI with a GET request with content type of application/json.
     *
     * @param  string  $uri
     * @param  array  $data
     * @param  array  $headers
     * @return $this
     */
    public function getJson($uri, array $headers = [])
    {
        return $this->requestJson('GET', $uri, [], $headers);
    }

    /**
     * Visit the given URI with a POST request with content type of application/json.
     *
     * @param  string  $uri
     * @param  array  $data
     * @param  array  $headers
     * @return $this
     */
    public function postJson($uri, array $data = [], array $headers = [])
    {
        return $this->requestJson('POST', $uri, $data, $headers);
    }

{'fraction_non_alphanumeric': 0.1360316129804814, 'fraction_numerical': 0.00023949227637408692, 'mean_word_length': 2.0979228486646884, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 28, 'https://': 2, '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': '4000112', 'n_tokens_mistral': 2409, 'n_tokens_neox': 2373, 'n_words': 664}