<commit_before><?php

namespace Oro\Bundle\TranslationBundle\Tests\Unit\Helper;

use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\Common\Persistence\ObjectManager;

use Oro\Bundle\TranslationBundle\Entity\Repository\TranslationRepository;
use Oro\Bundle\TranslationBundle\Entity\Translation;
use Oro\Bundle\TranslationBundle\Helper\TranslationHelper;

use Oro\Component\Testing\Unit\EntityTrait;

class TranslationHelperTest extends \PHPUnit_Framework_TestCase
{
    use EntityTrait;

    /** @var ManagerRegistry|\PHPUnit_Framework_MockObject_MockObject */
    protected $registry;

    /** @var TranslationRepository|\PHPUnit_Framework_MockObject_MockObject */
    protected $repository;

    /** @var TranslationHelper */
    protected $helper;

    protected function setUp()
    {
        $this->repository = $this->getMockBuilder(TranslationRepository::class)
            ->disableOriginalConstructor()
            ->getMock();

        $manager = $this->getMock(ObjectManager::class);
        $manager->expects($this->any())
            ->method('getRepository')
            ->with(Translation::class)
            ->willReturn($this->repository);

        $this->registry = $this->getMock(ManagerRegistry::class);
        $this->registry->expects($this->any())
            ->method('getManagerForClass')
            ->with(Translation::class)
            ->willReturn($manager);

        $this->helper = new TranslationHelper($this->registry);
    }

    public function testFindValues()
    {
        $keysPrefix = 'oro.trans';
        $locale = 'en';
        $domain = 'messages';
        $data = ['data'];

        $this->repository->expects($this->once())
            ->method('findValues')
            ->with($keysPrefix, $locale, $domain)
            ->willReturn($data);

        $this->assertEquals($data, $this->helper->findValues($keysPrefix, $locale, $domain));
    }

    public function testFindValue()
    {
        $key = 'oro.trans.test.key';
        $locale = 'en';
        $domain = 'messages';
        $data = (new Translation())->setValue('test_value');

        $this->repository->expects($this->once())
            ->method('findValue')
            ->with($key, $locale, $domain)
            ->willReturn($data);

        $this->assertEquals($data->getValue(), $this->helper->findValue($key, $locale, $domain));
    }

    public function testFindValueWithoutTranslation()
    {
        $key = 'oro.trans.test.key';
        $locale = 'en';
        $domain = 'messages';

        $this->repository->expects($this->once())
            ->method('findValue')
            ->with($key, $locale, $domain)
            ->willReturn(null);

        $this->assertNull($this->helper->findValue($key, $locale, $domain));
    }
}<commit_msg>BAP-12113: Add functional test for command and entity repository - updated unit tests<commit_after><?php

namespace Oro\Bundle\TranslationBundle\Tests\Unit\Helper;

use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\Common\Persistence\ObjectManager;

use Oro\Bundle\TranslationBundle\Entity\Repository\TranslationRepository;
use Oro\Bundle\TranslationBundle\Entity\Translation;
use Oro\Bundle\TranslationBundle\Helper\TranslationHelper;

use Oro\Component\Testing\Unit\EntityTrait;

class TranslationHelperTest extends \PHPUnit_Framework_TestCase
{
    use EntityTrait;

    /** @var ManagerRegistry|\PHPUnit_Framework_MockObject_MockObject */
    protected $registry;

    /** @var TranslationRepository|\PHPUnit_Framework_MockObject_MockObject */
    protected $repository;

    /** @var TranslationHelper */
    protected $helper;

    protected function setUp()
    {
        $this->repository = $this->getMockBuilder(TranslationRepository::class)
            ->disableOriginalConstructor()
            ->getMock();

        $manager = $this->getMock(ObjectManager::class);
        $manager->expects($this->any())
            ->method('getRepository')
            ->with(Translation::class)
            ->willReturn($this->repository);

        $this->registry = $this->getMock(ManagerRegistry::class);
        $this->registry->expects($this->any())
            ->method('getManagerForClass')
            ->with(Translation::class)
            ->willReturn($manager);

        $this->helper = new TranslationHelper($this->registry);
    }

    public function testFindValues()
    {
        $keysPrefix = 'oro.trans';
        $locale = 'en';
        $domain = 'messages';
        $data = ['data'];

        $this->repository->expects($this->once())
            ->method('findValues')
            ->with($keysPrefix, $locale, $domain)
            ->willReturn($data);

        $this->assertEquals($data, $this->helper->findValues($keysPrefix, $locale, $domain));
    }

    public function testFindValue()
    {
        $key = 'oro.trans.test.key';
        $locale = 'en';
        $domain = 'messages';
        $data = (new Translation())->setValue('test_value');

        $this->repository->expects($this->once())
            ->method('findTranslation')
            ->with($key, $locale, $domain)
            ->willReturn($data);

        $this->assertEquals($data->getValue(), $this->helper->findValue($key, $locale, $domain));
    }

    public function testFindValueWithoutTranslation()
    {
        $key = 'oro.trans.test.key';
        $locale = 'en';
        $domain = 'messages';

        $this->repository->expects($this->once())
            ->method('findTranslation')
            ->with($key, $locale, $domain)
            ->willReturn(null);

        $this->assertNull($this->helper->findValue($key, $locale, $domain));
    }
}
{'fraction_non_alphanumeric': 0.1542155816435432, 'fraction_numerical': 0.0008893632159373888, 'mean_word_length': 2.8382252559726964, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 103, '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': '2407339', 'n_tokens_mistral': 1543, 'n_tokens_neox': 1500, 'n_words': 243}