<commit_before><?php

namespace Tests\I18n;

use Knob\I18n\I18n;
use Knob\I18n\MissingLangFileException;
use PHPUnit\Framework\TestCase;

final class I18nTest extends TestCase
{
    const LANG_VALUE = 'My Lang Test';
    const LANG_KEY = 'lang1';
    const DEFAULT_LANG = self::LANG_KEY;
    const DEFAULT_LANG_FILE = 'default';

    public function testTransDefault()
    {
        $i18n = $this->aI18n();
        $this->assertEquals(
            'non_existing_trans',
            $i18n->trans('non_existing_trans')
        );
    }

    /**
     * @return I18n
     */
    private function aI18n()
    {
        return new I18n(new I18nConfigStub([
            'availableLanguages' => [
                self::LANG_KEY => self::LANG_VALUE,
            ],
            'defaultLanguage' => self::DEFAULT_LANG,
            'defaultLanguageFile' => self::DEFAULT_LANG_FILE,
        ]));
    }

    public function testTransDefaultFile()
    {
        $i18n = $this->aI18n();
        $this->assertEquals(
            'my value from default',
            $i18n->trans('my_key')
        );
    }

    public function testTransWithFileNameAndKey()
    {
        $i18n = $this->aI18n();
        $this->assertEquals(
            'my value from other_file',
            $i18n->trans('other_file.my_key')
        );
    }

    public function testForceLanguage()
    {
        $i18n = $this->aI18n();
        $this->assertEquals(
            'my value from default but lang2',
            $i18n->trans('my_key', [], 'lang2')
        );
    }

    public function testMissingLangFileButCallback()
    {
        $i18n = $this->aI18n();
        $this->assertEquals(
            'my value from other_file',
            $i18n->trans('other_file.my_key', [], 'lang2')
        );
    }

    public function testNonExistingFile()
    {
        $this->expectException(MissingLangFileException::class);

        $i18n = $this->aI18n();
        $this->assertEquals(
            'whatever, because the file does not exists',
            $i18n->trans('non_existing_file.my_key')
        );
    }

    public function test1ParamByString()
    {
        $i18n = $this->aI18n();
        $this->assertEquals(
            'my value',
            $i18n->trans('with_1_param [param:value]')
        );
    }

    public function test2ParamByString()
    {
        $i18n = $this->aI18n();
        $this->assertEquals(
            'my value1 and value2',
            $i18n->trans('with_2_params [param1:value1, param2:value2]')
        );
    }

    public function test1ParamByArray()
    {
        $i18n = $this->aI18n();
        $this->assertEquals(
            'my value',
            $i18n->trans('with_1_param', ['param' => 'value'])
        );
    }

    public function test2ParamByArray()
    {
        $i18n = $this->aI18n();
        $this->assertEquals(
            'my value1 and value2',
            $i18n->trans('with_2_params', [
                'param1' => 'value1',
                'param2' => 'value2'
            ])
        );
    }

    public function testDefaultLanguageValue()
    {
        $i18n = $this->aI18n();
        $this->assertEquals(
            self::DEFAULT_LANG,
            $i18n->defaultLanguage()
        );
    }

    public function testLanguageValue()
    {
        $i18n = $this->aI18n();
        $this->assertEquals(
            self::LANG_VALUE,
            $i18n->langValue(self::LANG_KEY)
        );
    }
}<commit_msg>Clean code from Tests<commit_after><?php

namespace Tests\I18n;

use Knob\I18n\I18n;
use Knob\I18n\MissingLangFileException;
use PHPUnit\Framework\TestCase;

final class I18nTest extends TestCase
{
    const LANG_VALUE = 'My Lang Test';
    const LANG_KEY = 'lang1';
    const DEFAULT_LANG = self::LANG_KEY;
    const DEFAULT_LANG_FILE = 'default';

    /**
     * @test
     */
    public function tryToTransANonExistingKey()
    {
        $i18n = $this->aI18n();
        $this->assertEquals(
            'non_existing_trans',
            $i18n->trans('non_existing_trans')
        );
    }

    /**
     * @return I18n
     */
    private function aI18n()
    {
        return new I18n(new I18nConfigStub([
            'availableLanguages' => [
                self::LANG_KEY => self::LANG_VALUE,
            ],
            'defaultLanguage' => self::DEFAULT_LANG,
            'defaultLanguageFile' => self::DEFAULT_LANG_FILE,
        ]));
    }

    /**
     * @test
     */
    public function transDefaultFile()
    {
        $i18n = $this->aI18n();
        $this->assertEquals(
            'my value from default',
            $i18n->trans('my_key')
        );
    }

    /**
     * @test
     */
    public function transWithFileNameAndKey()
    {
        $i18n = $this->aI18n();
        $this->assertEquals(
            'my value from other_file',
            $i18n->trans('other_file.my_key')
        );
    }

    /**
     * @test
     */
    public function forceLanguage()
    {
        $i18n = $this->aI18n();
        $this->assertEquals(
            'my value from default but lang2',
            $i18n->trans('my_key', [], 'lang2')
        );
    }

    /**
     * @test
     */
    public function missingLangFileButCallback()
    {
        $i18n = $this->aI18n();
        $this->assertEquals(
            'my value from other_file',
            $i18n->trans('other_file.my_key', [], 'lang2')
        );
    }

    /**
     * @test
     */
    public function nonExistingFile()
    {
        $this->expectException(MissingLangFileException::class);

        $i18n = $this->aI18n();
        $this->assertEquals(
            'whatever, because the file does not exists',
            $i18n->trans('non_existing_file.my_key')
        );
    }

    /**
     * @test
     */
    public function tryTo1ParamByString()
    {
        $i18n = $this->aI18n();
        $this->assertEquals(
            'my value',
            $i18n->trans('with_1_param [param:value]')
        );
    }

    /**
     * @test
     */
    public function tryTo2ParamByString()
    {
        $i18n = $this->aI18n();
        $this->assertEquals(
            'my value1 and value2',
            $i18n->trans('with_2_params [param1:value1, param2:value2]')
        );
    }

    /**
     * @test
     */
    public function tryTo1ParamByArray()
    {
        $i18n = $this->aI18n();
        $this->assertEquals(
            'my value',
            $i18n->trans('with_1_param', ['param' => 'value'])
        );
    }

    /**
     * @test
     */
    public function tryTo2ParamByArray()
    {
        $i18n = $this->aI18n();
        $this->assertEquals(
            'my value1 and value2',
            $i18n->trans('with_2_params', [
                'param1' => 'value1',
                'param2' => 'value2',
            ])
        );
    }

    public function tryToDefaultLanguageValue()
    {
        $i18n = $this->aI18n();
        $this->assertEquals(
            self::DEFAULT_LANG,
            $i18n->defaultLanguage()
        );
    }

    public function tryToLanguageValue()
    {
        $i18n = $this->aI18n();
        $this->assertEquals(
            self::LANG_VALUE,
            $i18n->langValue(self::LANG_KEY)
        );
    }
}
{'fraction_non_alphanumeric': 0.1414804469273743, 'fraction_numerical': 0.031843575418994415, 'mean_word_length': 1.7248858447488584, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 91, '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': '7192463', 'n_tokens_mistral': 2392, 'n_tokens_neox': 2246, 'n_words': 373}