<commit_before><?php

namespace spec\Noair;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

class MediatorSpec extends ObjectBehavior
{
    function it_is_initializable()
    {
        $this->shouldBeAnInstanceOf('Noair\Mediator');
    }

    function it_will_not_hold_unheard_events_by_default()
    {
        $this->holdUnheardEvents()->shouldBe(false);
    }

    function it_may_hold_unheard_events()
    {
        $this->holdUnheardEvents(true);

        $this->holdUnheardEvents()->shouldBe(true);
    }

    function it_clears_the_pending_list()
    {
        $this->holdUnheardEvents(true);

        $this->publish(new \Noair\Event('randomname'));
        $this->holdUnheardEvents(false);

        $this->held->shouldEqual([]);
    }

    function it_holds_the_pending_event()
    {
        $this->holdUnheardEvents(true);

        $this->publish(new \Noair\Event('randomname'));

        $this->held[0]->shouldBeAnInstanceOf('Noair\Event');
        $this->held[0]->name->shouldEqual('randomname');
    }

    function it_has_no_subscribers()
    {
        $this->shouldNotHaveSubscribers('randomname');
    }

    function it_can_register_basic_handlers()
    {
        $eventname = 'randomname';
        $callback = function() {};

        $this->subscribe([$eventname => [$callback]]);

        $this->shouldHaveSubscribers($eventname);
        $this->isSubscribed($eventname, $callback)->shouldBeInteger();
    }

    function it_can_register_time_handlers()
    {
        $eventname = 'timer';
        $callback = function() {};

        $this->subscribe([$eventname . ':10' => [$callback]]);

        $this->shouldHaveSubscribers($eventname);
        $this->isSubscribed($eventname, $callback)->shouldBeInteger();
    }

    function it_can_unregister_all_handlers()
    {
        $eventname = 'randomname';
        $callback = function() {};
        $this->subscribe([$eventname => [$callback]]);
        $this->subscribe([$eventname => [$callback]]);

        $this->unsubscribe($eventname);

        $this->shouldNotHaveSubscribers($eventname);
    }

    function it_can_unregister_specific_handlers()
    {
        $eventname = 'randomname';
        $callback1 = function() { return true; };
        $callback2 = function() { return false; };
        $this->subscribe([$eventname => [$callback1]]);
        $this->subscribe([$eventname => [$callback2]]);

        $this->unsubscribe($eventname, $callback1);

        $this->isSubscribed($eventname, $callback2)->shouldBeInteger();
        $this->isSubscribed($eventname, $callback1)->shouldReturn(false);
    }

    function it_can_publish_events()
    {
        $eventname = 'randomname';
        $callback = function() { return 'event handled'; };
        $this->subscribe([$eventname => [$callback]]);

        $this->publish(new \Noair\Event($eventname))->shouldReturn('event handled');
    }<commit_msg>updated unsubscribe() specs<commit_after><?php

namespace spec\Noair;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

class MediatorSpec extends ObjectBehavior
{
    function it_is_initializable()
    {
        $this->shouldBeAnInstanceOf('Noair\Mediator');
    }

    function it_will_not_hold_unheard_events_by_default()
    {
        $this->holdUnheardEvents()->shouldBe(false);
    }

    function it_may_hold_unheard_events()
    {
        $this->holdUnheardEvents(true);

        $this->holdUnheardEvents()->shouldBe(true);
    }

    function it_clears_the_pending_list()
    {
        $this->holdUnheardEvents(true);

        $this->publish(new \Noair\Event('randomname'));
        $this->holdUnheardEvents(false);

        $this->held->shouldEqual([]);
    }

    function it_holds_the_pending_event()
    {
        $this->holdUnheardEvents(true);

        $this->publish(new \Noair\Event('randomname'));

        $this->held[0]->shouldBeAnInstanceOf('Noair\Event');
        $this->held[0]->name->shouldEqual('randomname');
    }

    function it_has_no_subscribers()
    {
        $this->shouldNotHaveSubscribers('randomname');
    }

    function it_can_register_basic_handlers()
    {
        $eventname = 'randomname';
        $callback = function() {};

        $this->subscribe([$eventname => [$callback]]);

        $this->shouldHaveSubscribers($eventname);
        $this->isSubscribed($eventname, $callback)->shouldBeInteger();
    }

    function it_can_register_time_handlers()
    {
        $eventname = 'timer';
        $callback = function() {};

        $this->subscribe([$eventname . ':10' => [$callback]]);

        $this->shouldHaveSubscribers($eventname);
        $this->isSubscribed($eventname, $callback)->shouldBeInteger();
    }

    function it_can_unregister_all_handlers()
    {
        $eventname = 'randomname';
        $callback = function() {};
        $this->subscribe([$eventname => [$callback]]);
        $this->subscribe([$eventname => [$callback]]);

        $this->unsubscribe([$eventname => '*']);

        $this->shouldNotHaveSubscribers($eventname);
    }

    function it_can_unregister_specific_handlers()
    {
        $eventname = 'randomname';
        $callback1 = function() { return true; };
        $callback2 = function() { return false; };
        $this->subscribe([$eventname => [$callback1]]);
        $this->subscribe([$eventname => [$callback2]]);

        $this->unsubscribe([$eventname => $callback1]);

        $this->isSubscribed($eventname, $callback2)->shouldBeInteger();
        $this->isSubscribed($eventname, $callback1)->shouldReturn(false);
    }

    function it_can_publish_events()
    {
        $eventname = 'randomname';
        $callback = function() { return 'event handled'; };
        $this->subscribe([$eventname => [$callback]]);

        $this->publish(new \Noair\Event($eventname))->shouldReturn('event handled');
    }
{'fraction_non_alphanumeric': 0.16024866171645658, 'fraction_numerical': 0.003798998445864272, 'mean_word_length': 3.1253561253561255, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 101, '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': '6500596', 'n_tokens_mistral': 1799, 'n_tokens_neox': 1715, 'n_words': 220}