<commit_before><?php

/*
 * This file is part of the Sonata Project package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Sonata\AdminBundle\Tests\Translator\Extractor\JMSTranslatorBundle;

use JMS\TranslationBundle\Model\Message;
use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\AdminBundle\Admin\Pool;
use Sonata\AdminBundle\Translator\Extractor\JMSTranslatorBundle\AdminExtractor;

/**
 * Test for AdminExtractor.
 *
 * @author <NAME> <<EMAIL>>
 */
class AdminExtractorTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var AdminExtractor
     */
    private $adminExtractor;

    /**
     * @var Pool
     */
    private $pool;

    /**
     * @var AdminInterface
     */
    private $fooAdmin;

    /**
     * @var AdminInterface
     */
    private $barAdmin;

    public function setUp()
    {
        if (!interface_exists('JMS\TranslationBundle\Translation\ExtractorInterface')) {
            $this->markTestSkipped('JMS Translator Bundle does not exist');
        }

        $this->fooAdmin = $this->getMock('Sonata\AdminBundle\Admin\AdminInterface');
        $this->barAdmin = $this->getMock('Sonata\AdminBundle\Admin\AdminInterface');

        // php 5.3 BC
        $fooAdmin = $this->fooAdmin;
        $barAdmin = $this->barAdmin;

        $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
        $container->expects($this->any())
            ->method('get')
            ->will($this->returnCallback(function ($id) use ($fooAdmin, $barAdmin) {
                switch ($id) {
                    case 'foo_admin':
                        return $fooAdmin;
                    case 'bar_admin':
                        return $barAdmin;
                }

                return;
            }));

        $logger = $this->getMock('Psr\Log\LoggerInterface');

        $this->pool = new Pool($container, '', '');
        $this->pool->setAdminServiceIds(array('foo_admin', 'bar_admin'));

        $this->adminExtractor = new AdminExtractor($this->pool, $logger);
        $this->adminExtractor->setLogger($logger);
    }

    public function testExtractEmpty()
    {
        $catalogue = $this->adminExtractor->extract();

        $this->assertInstanceOf('JMS\TranslationBundle\Model\MessageCatalogue', $catalogue);
        $this->assertFalse($catalogue->has(new Message('foo', 'foo_admin_domain')));
    }

    public function testExtract()
    {
        // php 5.3 BC
        $translator = $this->adminExtractor;

        $tester = $this;
        $this->fooAdmin->expects($this->any())
            ->method('getShow')
            ->will($this->returnCallback(function () use ($translator, $tester) {
                $tester->assertEquals('foo', $translator->trans('foo', array(), 'foo_admin_domain'));
                $tester->assertEquals('foo', $translator->transChoice('foo', 1, array(), 'foo_admin_domain'));

                return;
            }));

        $catalogue = $this->adminExtractor->extract();

        $this->assertTrue($catalogue->has(new Message('foo', 'foo_admin_domain')));
        $this->assertFalse($catalogue->has(new Message('nonexistent', 'foo_admin_domain')));

        $this->assertInstanceOf('JMS\TranslationBundle\Model\Message', $catalogue->get('foo', 'foo_admin_domain'));

        $message = $catalogue->get('foo', 'foo_admin_domain');
        $this->assertSame('foo', $message->getId());
        $this->assertSame('foo_admin_domain', $message->getDomain());
    }

    public function testExtractWithException()
    {
        $this->setExpectedException('RuntimeException', 'Foo throws exception');

        $this->fooAdmin->expects($this->any())
            ->method('getShow')
            ->will($this->returnCallback(function () {
                throw new \RuntimeException('Foo throws exception');
            }));

        $catalogue = $this->adminExtractor->extract();
    }
}<commit_msg>Remove useless variable<commit_after><?php

/*
 * This file is part of the Sonata Project package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Sonata\AdminBundle\Tests\Translator\Extractor\JMSTranslatorBundle;

use JMS\TranslationBundle\Model\Message;
use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\AdminBundle\Admin\Pool;
use Sonata\AdminBundle\Translator\Extractor\JMSTranslatorBundle\AdminExtractor;

/**
 * Test for AdminExtractor.
 *
 * @author <NAME> <<EMAIL>>
 */
class AdminExtractorTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var AdminExtractor
     */
    private $adminExtractor;

    /**
     * @var Pool
     */
    private $pool;

    /**
     * @var AdminInterface
     */
    private $fooAdmin;

    /**
     * @var AdminInterface
     */
    private $barAdmin;

    public function setUp()
    {
        if (!interface_exists('JMS\TranslationBundle\Translation\ExtractorInterface')) {
            $this->markTestSkipped('JMS Translator Bundle does not exist');
        }

        $this->fooAdmin = $this->getMock('Sonata\AdminBundle\Admin\AdminInterface');
        $this->barAdmin = $this->getMock('Sonata\AdminBundle\Admin\AdminInterface');

        // php 5.3 BC
        $fooAdmin = $this->fooAdmin;
        $barAdmin = $this->barAdmin;

        $container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
        $container->expects($this->any())
            ->method('get')
            ->will($this->returnCallback(function ($id) use ($fooAdmin, $barAdmin) {
                switch ($id) {
                    case 'foo_admin':
                        return $fooAdmin;
                    case 'bar_admin':
                        return $barAdmin;
                }

                return;
            }));

        $logger = $this->getMock('Psr\Log\LoggerInterface');

        $this->pool = new Pool($container, '', '');
        $this->pool->setAdminServiceIds(array('foo_admin', 'bar_admin'));

        $this->adminExtractor = new AdminExtractor($this->pool, $logger);
        $this->adminExtractor->setLogger($logger);
    }

    public function testExtractEmpty()
    {
        $catalogue = $this->adminExtractor->extract();

        $this->assertInstanceOf('JMS\TranslationBundle\Model\MessageCatalogue', $catalogue);
        $this->assertFalse($catalogue->has(new Message('foo', 'foo_admin_domain')));
    }

    public function testExtract()
    {
        // php 5.3 BC
        $translator = $this->adminExtractor;

        $tester = $this;
        $this->fooAdmin->expects($this->any())
            ->method('getShow')
            ->will($this->returnCallback(function () use ($translator, $tester) {
                $tester->assertEquals('foo', $translator->trans('foo', array(), 'foo_admin_domain'));
                $tester->assertEquals('foo', $translator->transChoice('foo', 1, array(), 'foo_admin_domain'));

                return;
            }));

        $catalogue = $this->adminExtractor->extract();

        $this->assertTrue($catalogue->has(new Message('foo', 'foo_admin_domain')));
        $this->assertFalse($catalogue->has(new Message('nonexistent', 'foo_admin_domain')));

        $this->assertInstanceOf('JMS\TranslationBundle\Model\Message', $catalogue->get('foo', 'foo_admin_domain'));

        $message = $catalogue->get('foo', 'foo_admin_domain');
        $this->assertSame('foo', $message->getId());
        $this->assertSame('foo_admin_domain', $message->getDomain());
    }

    public function testExtractWithException()
    {
        $this->setExpectedException('RuntimeException', 'Foo throws exception');

        $this->fooAdmin->expects($this->any())
            ->method('getShow')
            ->will($this->returnCallback(function () {
                throw new \RuntimeException('Foo throws exception');
            }));

        $this->adminExtractor->extract();
    }
}
{'fraction_non_alphanumeric': 0.15346349956473077, 'fraction_numerical': 0.0012436264146250466, 'mean_word_length': 2.6405613399728383, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 133, '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': '139686', 'n_tokens_mistral': 2319, 'n_tokens_neox': 2239, 'n_words': 387}