<commit_before><?php

use Bone\Server\I18nHandler;
use Bone\Service\TranslatorFactory;
use Codeception\TestCase\Test;
use Zend\Diactoros\ServerRequest;
use Zend\Diactoros\Uri;
use Zend\I18n\Translator\Loader\Gettext;

class I18HandlerTest extends Test
{
    /**
     * @var \UnitTester
     */
    protected $tester;

    /** @var I18nHandler $middleware */
    private $middleware;

    private $translator;

    public function _before()
    {
        $factory = new TranslatorFactory();
        $config = [
            'enabled' => false,
            'translations_dir' => 'tests/_data/translations',
            'type' => Gettext::class,
            'default_locale' => 'en_PI',
            'supported_locales' => ['en_PI', 'en_GB', 'nl_BE', 'fr_BE'],
            'date_format' => 'd/m/Y',
        ];
        $this->translator = $factory->createTranslator($config);
        $this->middleware = new I18nHandler($this->translator, $config['supported_locales']);

    }

    /**
     * @throws \League\Route\Http\Exception\NotFoundException
     */
    public function testLocale()
    {
        $locale = Locale::getDefault();
        $request = new ServerRequest([], [], new Uri('https://awesome.scot/en_PI/somepage'));
        $request = $this->middleware->handleI18n($request);
        $this->assertEquals('/somepage', $request->getUri()->getPath());
        $newLocale = Locale::getDefault();
        $this->assertTrue($locale !== $newLocale);
        $this->assertEquals('en_PI', $newLocale);
    }

    /**
     * @throws \League\Route\Http\Exception\NotFoundException
     */
    public function testUnsupportedLocale()
    {
        $locale = Locale::getDefault();
        $request = new ServerRequest([], [], new Uri('https://awesome.scot/es_ES/somepage'));
        $request = $this->middleware->handleI18n($request);
        $this->assertEquals('/es_ES/somepage', $request->getUri()->getPath());
        $newLocale = Locale::getDefault();
        $this->assertTrue($locale === $newLocale);
    }

    /**
     * @throws \League\Route\Http\Exception\NotFoundException
     */
    public function testRemoveLocale()
    {
        $locale = Locale::getDefault();
        $request = new ServerRequest([], [], new Uri('https://awesome.scot/es_ES/somepage'));
        $request = $this->middleware->removeI18n($request);
        $this->assertEquals('/somepage', $request->getUri()->getPath());
        $newLocale = Locale::getDefault();
        $this->assertTrue($locale === $newLocale);
    }
}<commit_msg>fix contrustor in test<commit_after><?php

use Bone\Server\I18nHandler;
use Bone\Service\TranslatorFactory;
use Codeception\TestCase\Test;
use Zend\Diactoros\ServerRequest;
use Zend\Diactoros\Uri;
use Zend\I18n\Translator\Loader\Gettext;

class I18HandlerTest extends Test
{
    /**
     * @var \UnitTester
     */
    protected $tester;

    /** @var I18nHandler $middleware */
    private $middleware;

    private $translator;

    public function _before()
    {
        $factory = new TranslatorFactory();
        $config = [
            'enabled' => false,
            'translations_dir' => 'tests/_data/translations',
            'type' => Gettext::class,
            'default_locale' => 'en_PI',
            'supported_locales' => ['en_PI', 'en_GB', 'nl_BE', 'fr_BE'],
            'date_format' => 'd/m/Y',
        ];
        $this->translator = $factory->createTranslator($config);
        $this->middleware = new I18nHandler($this->translator, $config['supported_locales'], $config['default_locale']);

    }

    /**
     * @throws \League\Route\Http\Exception\NotFoundException
     */
    public function testLocale()
    {
        $locale = Locale::getDefault();
        $request = new ServerRequest([], [], new Uri('https://awesome.scot/en_PI/somepage'));
        $request = $this->middleware->handleI18n($request);
        $this->assertEquals('/somepage', $request->getUri()->getPath());
        $newLocale = Locale::getDefault();
        $this->assertTrue($locale !== $newLocale);
        $this->assertEquals('en_PI', $newLocale);
    }

    /**
     * @throws \League\Route\Http\Exception\NotFoundException
     */
    public function testUnsupportedLocale()
    {
        $locale = Locale::getDefault();
        $request = new ServerRequest([], [], new Uri('https://awesome.scot/es_ES/somepage'));
        $request = $this->middleware->handleI18n($request);
        $this->assertEquals('/es_ES/somepage', $request->getUri()->getPath());
        $newLocale = Locale::getDefault();
        $this->assertTrue($locale === $newLocale);
    }

    /**
     * @throws \League\Route\Http\Exception\NotFoundException
     */
    public function testRemoveLocale()
    {
        $locale = Locale::getDefault();
        $request = new ServerRequest([], [], new Uri('https://awesome.scot/es_ES/somepage'));
        $request = $this->middleware->removeI18n($request);
        $this->assertEquals('/somepage', $request->getUri()->getPath());
        $newLocale = Locale::getDefault();
        $this->assertTrue($locale === $newLocale);
    }
}
{'fraction_non_alphanumeric': 0.1715415019762846, 'fraction_numerical': 0.006324110671936759, 'mean_word_length': 2.87816091954023, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 61, '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': '1542074', 'n_tokens_mistral': 1547, 'n_tokens_neox': 1515, 'n_words': 240}