/** * We can bind and then unbind. */ function testBindThenUnbind() { $bind = Events::on('test_simple', array($this, 'onTestSimple')); try { Events::trigger('test_simple', "cat"); $this->assertEquals(array("cat"), $this->last_simple_data); } finally { Events::unbind($bind); } Events::trigger('test_simple', "dog"); $this->assertEquals(array("cat"), $this->last_simple_data); // hasn't changed }
/** * However we can capture missing strings using the event framework. */ function testEventIsThrown() { global $_test_event_is_thrown; $_test_event_is_thrown = false; $handler = \Openclerk\Events::on('i18n_missing_string', function ($string) { global $_test_event_is_thrown; $_test_event_is_thrown = $string; }); t("a missing string"); $this->assertEquals(array("locale" => "fr", "key" => "a missing string"), $_test_event_is_thrown); // and be a good events citizen \Openclerk\Events::unbind($handler); }