<commit_before><?php
/*
 * This file is part of PhergieDns.
 *
 ** (c) 2013 - 2014 <NAME>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace WyriHaximus\Phergie\Plugin\Dns;

/**
 * Tests for the Plugin class.
 *
 * @category Phergie
 * @package WyriHaximus\Phergie\Plugin\Dns
 */
class PluginTest extends \PHPUnit_Framework_TestCase
{

    public function testGetSubscribedEvents()
    {
        $plugin = new Plugin();
        $subscribedEvents = $plugin->getSubscribedEvents();
        $this->assertInternalType('array', $subscribedEvents);
        $this->assertSame(array(
                'command.dns' => 'handleDnsCommand'
        ), $subscribedEvents);
    }

    public function testGetSubscribedEventsCustomCommandName()
    {
        $plugin = new Plugin(array(
            'command' => 'dnsCustomName',
        ));
        $subscribedEvents = $plugin->getSubscribedEvents();
        $this->assertInternalType('array', $subscribedEvents);
        $this->assertSame(array(
            'command.dnsCustomName' => 'handleDnsCommand'
        ), $subscribedEvents);
    }

    public function testHandleDnsCommand()
    {
        $resolver = $this->getMock('React\Dns\Resolver\Resolver', array(
            'resolve',
        ), array(
            '8.8.8.8:53',
            $this->getMock('React\Dns\Query\ExecutorInterface'),
        ));
        $deferred = new \React\Promise\Deferred();
        $resolver->expects($this->once())
            ->method('resolve')
            ->with('wyrihaximus.net')
            ->willReturn($deferred->promise());

        $plugin = new Plugin(array(
            'resolver' => $resolver,
        ));

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

        $event = $this->getMock('Phergie\Irc\Plugin\React\Command\CommandEvent', array(
            'getCustomParams',
            'getTargets',
        ));
        $event->expects($this->once())
            ->method('getCustomParams')
            ->with()
            ->willReturn(array(
                'wyrihaximus.net',
            ));
        $event->expects($this->once())
            ->method('getTargets')
            ->with()
            ->willReturn(array(
                'WyriHaximus',
            ));

        $queue = $this->getMock('Phergie\Irc\Bot\React\EventQueueInterface', array(
            'ircPrivmsg',
            'extract',
            'setPrefix',
            'ircPass',
            'ircNick',
            'ircUser',
            'ircServer',
            'ircOper',
            'ircQuit',
            'ircJoin',
            'ircPart',
            'ircMode',
            'ircSquit',
            'ircTopic',
            'ircNames',
            'ircList',
            'ircInvite',
            'ircKick',
            'ircVersion',
            'ircStats',
            'ircLinks',
            'ircTime',
            'ircConnect',
            'ircTrace',
            'ircAdmin',
            'ircInfo',
            'ircNotice',
            'ircWho',
            'ircWhois',
            'ircWhowas',
            'ircKill',
            'ircPing',
            'ircPong',
            'ircError',
            'ircAway',
            'ircRehash',
            'ircRestart',
            'ircSummon',
            'ircUsers',
            'ircWallops',
            'ircUserhost',
            'ircIson',
            'ctcpFinger',
            'ctcpFingerResponse',
            'ctcpVersion',
            'ctcpVersionResponse',
            'ctcpSource',
            'ctcpSourceResponse',
            'ctcpUserinfo',
            'ctcpUserinfoResponse',
            'ctcpClientinfo',
            'ctcpClientinfoResponse',
            'ctcpErrmsg',
            'ctcpErrmsgResponse',
            'ctcpPing',
            'ctcpPingResponse',
            'ctcpTime',
            'ctcpTimeResponse',
            'ctcpAction',
            'ctcpActionResponse',
            'current',
            'next',
            'key',
            'valid',
            'rewind',
            'count',
        ));
        $queue->expects($this->once())
            ->method('ircPrivmsg')
            ->with('WyriHaximus', 'wyrihaximus.net: 1.2.3.4');

        $plugin->handleDnsCommand($event, $queue);

        $deferred->resolve('172.16.58.3');
    }

    public function testGetResolver()
    {
        $plugin = new Plugin(array(
            'dnsServer' => '172.16.31.10',
        ));

        $plugin->setLoop($this->getMock('React\EventLoop\LoopInterface'));

        $factory = $this->getMock('React\Dns\Resolver\Factory', array(
            'createCached',
        ));
        $factory->expects($this->once())
            ->method('createCached')
            ->with('172.16.31.10');

        $this->assertInstanceOf('React\Dns\Resolver\Resolver', $plugin->getResolver());
    }
}<commit_msg>Additional testing to make sure the getResolver method does it's work correctly<commit_after><?php
/*
 * This file is part of PhergieDns.
 *
 ** (c) 2013 - 2014 <NAME>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace WyriHaximus\Phergie\Plugin\Dns;

/**
 * Tests for the Plugin class.
 *
 * @category Phergie
 * @package WyriHaximus\Phergie\Plugin\Dns
 */
class PluginTest extends \PHPUnit_Framework_TestCase
{

    public function testGetSubscribedEvents()
    {
        $plugin = new Plugin();
        $subscribedEvents = $plugin->getSubscribedEvents();
        $this->assertInternalType('array', $subscribedEvents);
        $this->assertSame(array(
                'command.dns' => 'handleDnsCommand'
        ), $subscribedEvents);
    }

    public function testGetSubscribedEventsCustomCommandName()
    {
        $plugin = new Plugin(array(
            'command' => 'dnsCustomName',
        ));
        $subscribedEvents = $plugin->getSubscribedEvents();
        $this->assertInternalType('array', $subscribedEvents);
        $this->assertSame(array(
            'command.dnsCustomName' => 'handleDnsCommand'
        ), $subscribedEvents);
    }

    public function testHandleDnsCommand()
    {
        $resolver = $this->getMock('React\Dns\Resolver\Resolver', array(
            'resolve',
        ), array(
            '8.8.8.8:53',
            $this->getMock('React\Dns\Query\ExecutorInterface'),
        ));
        $deferred = new \React\Promise\Deferred();
        $resolver->expects($this->once())
            ->method('resolve')
            ->with('wyrihaximus.net')
            ->willReturn($deferred->promise());

        $plugin = new Plugin(array(
            'resolver' => $resolver,
        ));

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

        $event = $this->getMock('Phergie\Irc\Plugin\React\Command\CommandEvent', array(
            'getCustomParams',
            'getTargets',
        ));
        $event->expects($this->once())
            ->method('getCustomParams')
            ->with()
            ->willReturn(array(
                'wyrihaximus.net',
            ));
        $event->expects($this->once())
            ->method('getTargets')
            ->with()
            ->willReturn(array(
                'WyriHaximus',
            ));

        $queue = $this->getMock('Phergie\Irc\Bot\React\EventQueueInterface', array(
            'ircPrivmsg',
            'extract',
            'setPrefix',
            'ircPass',
            'ircNick',
            'ircUser',
            'ircServer',
            'ircOper',
            'ircQuit',
            'ircJoin',
            'ircPart',
            'ircMode',
            'ircSquit',
            'ircTopic',
            'ircNames',
            'ircList',
            'ircInvite',
            'ircKick',
            'ircVersion',
            'ircStats',
            'ircLinks',
            'ircTime',
            'ircConnect',
            'ircTrace',
            'ircAdmin',
            'ircInfo',
            'ircNotice',
            'ircWho',
            'ircWhois',
            'ircWhowas',
            'ircKill',
            'ircPing',
            'ircPong',
            'ircError',
            'ircAway',
            'ircRehash',
            'ircRestart',
            'ircSummon',
            'ircUsers',
            'ircWallops',
            'ircUserhost',
            'ircIson',
            'ctcpFinger',
            'ctcpFingerResponse',
            'ctcpVersion',
            'ctcpVersionResponse',
            'ctcpSource',
            'ctcpSourceResponse',
            'ctcpUserinfo',
            'ctcpUserinfoResponse',
            'ctcpClientinfo',
            'ctcpClientinfoResponse',
            'ctcpErrmsg',
            'ctcpErrmsgResponse',
            'ctcpPing',
            'ctcpPingResponse',
            'ctcpTime',
            'ctcpTimeResponse',
            'ctcpAction',
            'ctcpActionResponse',
            'current',
            'next',
            'key',
            'valid',
            'rewind',
            'count',
        ));
        $queue->expects($this->once())
            ->method('ircPrivmsg')
            ->with('WyriHaximus', 'wyrihaximus.net: 172.16.58.3');

        $plugin->handleDnsCommand($event, $queue);

        $deferred->resolve('172.16.58.3');
    }

    public function testGetResolver()
    {
        $plugin = new Plugin(array(
            'dnsServer' => '172.16.31.10',
        ));

        $plugin->setLoop($this->getMock('React\EventLoop\LoopInterface'));

        $factory = $this->getMock('React\Dns\Resolver\Factory', array(
            'createCached',
        ));
        $factory->expects($this->once())
            ->method('createCached')
            ->with('172.16.31.10')
            ->willReturn('foo:bar');

        $this->assertSame('foo:bar', $plugin->getResolver($factory));
    }

    public function testGetResolverBare()
    {
        $plugin = new Plugin(array(
            'dnsServer' => '172.16.31.10',
        ));

        $plugin->setLoop($this->getMock('React\EventLoop\LoopInterface'));

        $this->assertInstanceOf('React\Dns\Resolver\Resolver', $plugin->getResolver());
    }
}
{'fraction_non_alphanumeric': 0.14463254721597024, 'fraction_numerical': 0.00988355024953518, 'mean_word_length': 1.651790347690711, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 107, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 11, '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': '7654574', 'n_tokens_mistral': 3094, 'n_tokens_neox': 2897, 'n_words': 443}