<commit_before><?php

namespace WyriHaximus\React\Tests\ChildProcess\Messenger;

use Phake;
use WyriHaximus\React\ChildProcess\Messenger\Messenger;

class MessengerTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var React\EventLoop\LoopInterface
     */
    protected $loop;

    /**
     * @var React\ChildProcess\Process
     */
    protected $process;

    public function setUp()
    {
        $this->loop = Phake::mock('React\EventLoop\LoopInterface');
        $this->process = Phake::mock('React\ChildProcess\Process');
        $this->process->stdin = Phake::mock('React\Stream\Stream');
        $this->process->stdout = Phake::mock('React\Stream\Stream');
        $this->process->stderr = Phake::mock('React\Stream\Stream');
    }

    public function tearDown()
    {
        unset($this->process, $this->loop);
    }

    public function testStart()
    {
        (new Messenger($this->process))->start($this->loop);
        Phake::inOrder(
            Phake::verify($this->process)->start($this->loop, Messenger::INTERVAL),
            Phake::verify($this->process->stdout)->on('data', $this->isType('callable')),
            Phake::verify($this->process->stderr)->on('data', $this->isType('callable'))
        );
    }
}
<commit_msg>Basic RPC's interaction test<commit_after><?php

namespace WyriHaximus\React\Tests\ChildProcess\Messenger;

use Phake;
use React\EventLoop\Factory as EventLoopFactory;
use React\Promise\Deferred;
use WyriHaximus\React\ChildProcess\Messenger\Factory;

class MessengerTest extends \PHPUnit_Framework_TestCase
{

    public function testSetAndHasRpc()
    {
        $loop = EventLoopFactory::create();
        $messenger = Factory::child($loop);

        $payload = [
            'a',
            'b',
            'c',
        ];
        $deferred = new Deferred();
        $callableFired = false;
        $callable = function (array $passedPayload, Deferred $passedDeferred) use (&$callableFired, $payload, $deferred) {
            $this->assertEquals($payload, $passedPayload);
            $this->assertEquals($deferred, $passedDeferred);
            $callableFired = true;
        };

        $messenger->registerRpc('test', $callable);
        $this->assertFalse($messenger->hasRpc('tset'));
        $this->assertTrue($messenger->hasRpc('test'));

        $messenger->callRpc('test', $payload, $deferred);

        $this->assertTrue($callableFired);
    }
}

{'fraction_non_alphanumeric': 0.15741507870753935, 'fraction_numerical': 0.0, 'mean_word_length': 3.0183028286189684, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 36, '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': '3360022', 'n_tokens_mistral': 745, 'n_tokens_neox': 726, 'n_words': 109}