<commit_before><?php

/*
 * This file is part of PhuninNode.
 *
 ** (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\PhuninNode\Tests\Plugins;

/**
 * Class AbstractPluginTest
 * @package WyriHaximus\PhuninNode\Tests\Plugins
 */
abstract class AbstractPluginTest extends \PHPUnit_Framework_TestCase
{

    protected $plugin;

    public function setUp()
    {
        parent::setUp();

        $this->loop = $this->getMock('\React\EventLoop\StreamSelectLoop');
        $this->socket = $this->getMock(
            '\React\Socket\Server',
            [
                'on',
                'write',
            ],
            [
                $this->loop,
                '0.0.0.0',
                12345
            ]
        );

        $this->node = $this->getMock(
            '\WyriHaximus\PhuninNode\Node',
            [
                'getPlugins',
                'getPlugin',
                'getValues',
                'addPlugin',
            ],
            [
                $this->loop,
                $this->socket,
            ]
        );

        $this->plugin->setNode($this->node);

        $this->plugins = new \SplObjectStorage();
        $plugin = $this->getMock(
            '\WyriHaximus\PhuninNode\PluginInterface',
            [
                'getSlug',
                'getConfiguration',
                'setNode',
                'getValues',
            ]
        );
        $plugin->method('getSlug')
            ->willReturn('a');
        $plugin->method('getConfiguration')
            ->will(
                $this->returnCallback(
                    function ($resolver) {
                        $configuration = new \WyriHaximus\PhuninNode\PluginConfiguration();
                        $configuration->setPair('graph_category', 'a');
                        $resolver->resolve($configuration);
                    }
                )
            );
        $this->node->method('getPlugins')
            ->willReturn($this->plugins);
        $this->plugins->attach($plugin);
    }

    public function tearDown()
    {
        unset($this->loop, $this->socket, $this->node, $this->plugins);
    }

    public function testPlugin()
    {
        $classImplements = class_implements($this->plugin);
        $this->assertTrue(isset($classImplements['WyriHaximus\PhuninNode\PluginInterface']));
    }

    public function testGetConfiguration()
    {

        $callbackRan = false;
        $deferred = new \React\Promise\Deferred();
        $deferred->promise()->then(
            function ($configuration) use (&$callbackRan) {
                $callbackRan = true;
                $this->assertInstanceOf('WyriHaximus\PhuninNode\PluginConfiguration', $configuration);
            }
        );
        $this->plugin->getConfiguration($deferred);
        $this->assertTrue($callbackRan);

        $callbackRan = false;
        $deferred = new \React\Promise\Deferred();
        $deferred->promise()->then(
            function ($configuration) use (&$callbackRan) {
                $callbackRan = true;
                $this->assertInstanceOf('WyriHaximus\PhuninNode\PluginConfiguration', $configuration);
            }
        );
        $this->plugin->getConfiguration($deferred);
        $this->assertTrue($callbackRan);
    }

    public function testGetConfigurationValues()
    {

        $callbackRan = false;
        $deferred = new \React\Promise\Deferred();
        $deferred->promise()->then(
            function ($configuration) use (&$callbackRan) {
                $callbackRan = true;
                foreach ($configuration as $value) {
                    $this->assertInstanceOf('WyriHaximus\PhuninNode\Value', $value);
                }
            }
        );
        $this->plugin->getConfiguration($deferred);
        $this->assertTrue($callbackRan);
    }

    public function testGetValues()
    {

        $callbackRan = false;
        $deferred = new \React\Promise\Deferred();
        $deferred->promise()->then(
            function ($values) use (&$callbackRan) {
                $callbackRan = true;
                $this->assertInstanceOf('SplObjectStorage', $values);
            }
        );
        $this->plugin->getValues($deferred);
        $this->assertTrue($callbackRan);

        $callbackRan = false;
        $deferred = new \React\Promise\Deferred();
        $deferred->promise()->then(
            function ($values) use (&$callbackRan) {
                $callbackRan = true;
                $this->assertInstanceOf('WyriHaximus\PhuninNode\PluginConfiguration', $values);
            }
        );
        $this->plugin->getValues($deferred);
        $this->assertTrue($callbackRan);
    }

    public function testGetValuesValues()
    {

        $callbackRan = false;
        $deferred = new \React\Promise\Deferred();
        $deferred->promise()->then(
            function ($values) use (&$callbackRan) {
                $callbackRan = true;
                foreach ($values as $value) {
                    $this->assertInstanceOf('WyriHaximus\PhuninNode\Value', $value);
                }
            }
        );
        $this->plugin->getValues($deferred);
        $this->assertTrue($callbackRan);
    }
}
<commit_msg>Callbacks wheren't properly testing instance types<commit_after><?php

/*
 * This file is part of PhuninNode.
 *
 ** (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\PhuninNode\Tests\Plugins;

/**
 * Class AbstractPluginTest
 * @package WyriHaximus\PhuninNode\Tests\Plugins
 */
abstract class AbstractPluginTest extends \PHPUnit_Framework_TestCase
{

    protected $plugin;

    public function setUp()
    {
        parent::setUp();

        $this->loop = $this->getMock('\React\EventLoop\StreamSelectLoop');
        $this->socket = $this->getMock(
            '\React\Socket\Server',
            [
                'on',
                'write',
            ],
            [
                $this->loop,
                '0.0.0.0',
                12345
            ]
        );

        $this->node = $this->getMock(
            '\WyriHaximus\PhuninNode\Node',
            [
                'getPlugins',
                'getPlugin',
                'getValues',
                'addPlugin',
            ],
            [
                $this->loop,
                $this->socket,
            ]
        );

        $this->plugin->setNode($this->node);

        $this->plugins = new \SplObjectStorage();
        $plugin = $this->getMock(
            '\WyriHaximus\PhuninNode\PluginInterface',
            [
                'getSlug',
                'getConfiguration',
                'setNode',
                'getValues',
            ]
        );
        $plugin->method('getSlug')
            ->willReturn('a');
        $plugin->method('getConfiguration')
            ->will(
                $this->returnCallback(
                    function ($resolver) {
                        $configuration = new \WyriHaximus\PhuninNode\PluginConfiguration();
                        $configuration->setPair('graph_category', 'a');
                        $resolver->resolve($configuration);
                    }
                )
            );
        $this->node->method('getPlugins')
            ->willReturn($this->plugins);
        $this->plugins->attach($plugin);
    }

    public function tearDown()
    {
        unset($this->loop, $this->socket, $this->node, $this->plugins);
    }

    public function testPlugin()
    {
        $classImplements = class_implements($this->plugin);
        $this->assertTrue(isset($classImplements['WyriHaximus\PhuninNode\PluginInterface']));
    }

    public function testGetConfiguration()
    {

        $callbackRan = false;
        $callbackArgument = null;
        $deferred = new \React\Promise\Deferred();
        $deferred->promise()->then(
            function ($configuration) use (&$callbackRan, &$callbackArgument) {
                $callbackRan = true;
                $callbackArgument = $configuration;
            }
        );
        $this->plugin->getConfiguration($deferred);
        $this->assertTrue($callbackRan);
        $this->assertInstanceOf('WyriHaximus\PhuninNode\PluginConfiguration', $callbackArgument);

        $callbackRan = false;
        $callbackArgument = null;
        $deferred = new \React\Promise\Deferred();
        $deferred->promise()->then(
            function ($configuration) use (&$callbackRan, &$callbackArgument) {
                $callbackRan = true;
                $callbackArgument = $configuration;
            }
        );
        $this->plugin->getConfiguration($deferred);
        $this->assertTrue($callbackRan);
        $this->assertInstanceOf('WyriHaximus\PhuninNode\PluginConfiguration', $callbackArgument);
    }

    public function testGetConfigurationValues()
    {

        $callbackRan = false;
        $callbackArgument = null;
        $deferred = new \React\Promise\Deferred();
        $deferred->promise()->then(
            function ($configuration) use (&$callbackRan, &$callbackArgument) {
                $callbackRan = true;
                $callbackArgument = $configuration;
            }
        );
        $this->plugin->getConfiguration($deferred);
        $this->assertTrue($callbackRan);
        foreach ($callbackArgument as $value) {
            $this->assertInstanceOf('WyriHaximus\PhuninNode\Value', $value);
        }
    }

    public function testGetValues()
    {

        $callbackRan = false;
        $callbackArgument = null;
        $deferred = new \React\Promise\Deferred();
        $deferred->promise()->then(
            function ($values) use (&$callbackRan, &$callbackArgument) {
                $callbackRan = true;
                $callbackArgument = $values;
            }
        );
        $this->plugin->getValues($deferred);
        $this->assertTrue($callbackRan);
        $this->assertInstanceOf('SplObjectStorage', $callbackArgument);

        foreach ($callbackArgument as $value) {
            $this->assertTrue(strlen($value->getKey()) > 0);
            $this->assertTrue(strlen($value->getValue()) > 0);
        }

        $callbackRan = false;
        $callbackArgument = null;
        $deferred = new \React\Promise\Deferred();
        $deferred->promise()->then(
            function ($values) use (&$callbackRan, &$callbackArgument) {
                $callbackRan = true;
                $callbackArgument = $values;
            }
        );

        $this->plugin->getValues($deferred);
        $this->assertTrue($callbackRan);
        $this->assertInstanceOf('SplObjectStorage', $callbackArgument);
    }

    public function testGetValuesValues()
    {

        $callbackRan = false;
        $callbackArgument = null;
        $deferred = new \React\Promise\Deferred();
        $deferred->promise()->then(
            function ($values) use (&$callbackRan, &$callbackArgument) {
                $callbackRan = true;
                $callbackArgument = $values;
            }
        );
        $this->plugin->getValues($deferred);
        $this->assertTrue($callbackRan);
        foreach ($callbackArgument as $value) {
            $this->assertInstanceOf('WyriHaximus\PhuninNode\Value', $value);
        }
    }
}

{'fraction_non_alphanumeric': 0.13424753253559263, 'fraction_numerical': 0.0031443794217835617, 'mean_word_length': 1.7657004830917875, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 149, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '1671497', 'n_tokens_mistral': 3181, 'n_tokens_neox': 3054, 'n_words': 487}