/** * @return \Symfony\Component\EventDispatcher\EventDispatcher */ public function createEventDispatcher() { $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $dispatcher->addListener('hook_civicrm_post::Activity', array('\\Civi\\CCase\\Events', 'fireCaseChange')); $dispatcher->addListener('hook_civicrm_post::Case', array('\\Civi\\CCase\\Events', 'fireCaseChange')); $dispatcher->addListener('hook_civicrm_caseChange', array('\\Civi\\CCase\\Events', 'delegateToXmlListeners')); $dispatcher->addListener('hook_civicrm_caseChange', array('\\Civi\\CCase\\SequenceListener', 'onCaseChange_static')); return $dispatcher; }
/** * Test default_configs * * @dataProvider default_configs_data */ public function test_default_configs($allow, $require, $registered, $is_bot, $expected) { $this->config['allow_birthdays'] = $allow; $this->config['birthday_require'] = $require; $this->set_listener(); $this->template->expects($this->exactly($expected))->method('assign_vars'); $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $dispatcher->addListener('core.user_setup', array($this->listener, 'default_configs')); $event_data = array('user_data' => array('is_bot' => $is_bot, 'is_registered' => $registered)); $event = new \phpbb\event\data(compact($event_data)); $dispatcher->dispatch('core.user_setup', $event); }
public function testDispatchingEventsOnJob() { // Worker mock $worker = $this->getMockBuilder('\\GearmanWorker')->disableOriginalConstructor()->getMock(); $worker->method('addServer')->willReturn(true); // Wrapper mock $workers = array(0 => array('className' => "Mmoreram\\GearmanBundle\\Tests\\Service\\Mocks\\SingleCleanFile", 'fileName' => dirname(__FILE__) . '/Mocks/SingleCleanFile.php', 'callableName' => null, 'description' => "test", 'service' => false, 'servers' => array(), 'iterations' => 1, 'timeout' => null, 'minimumExecutionTime' => null, 'jobs' => array(0 => array('callableName' => "test", 'methodName' => "test", 'realCallableName' => "test", 'jobPrefix' => NULL, 'realCallableNameNoPrefix' => "test", 'description' => "test", 'iterations' => 1, 'servers' => array(), 'defaultMethod' => "doBackground", 'minimumExecutionTime' => null, 'timeout' => null)))); $wrapper = $this->getMockBuilder('Mmoreram\\GearmanBundle\\Service\\GearmanCacheWrapper')->disableOriginalConstructor()->getMock(); $wrapper->method('getWorkers')->willReturn($workers); // Prepare a dispatcher to listen to tested events $startingFlag = false; $executedFlag = false; $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $dispatcher->addListener(GearmanEvents::GEARMAN_WORK_STARTING, function () use(&$startingFlag) { $startingFlag = true; }); $dispatcher->addListener(GearmanEvents::GEARMAN_WORK_EXECUTED, function () use(&$executedFlag) { $executedFlag = true; }); // Create the service under test $service = new GearmanExecute($wrapper, array()); $service->setEventDispatcher($dispatcher); // We need a job object, this part could be improved $object = new \Mmoreram\GearmanBundle\Tests\Service\Mocks\SingleCleanFile(); // Finalize worker mock by making it call our job object // This is normally handled by Gearman, but for test purpose we must simulate it $worker->method('work')->will($this->returnCallback(function () use($service, $object) { $service->handleJob(new \GearmanJob(), array('job_object_instance' => $object, 'job_method' => 'myMethod', 'jobs' => array())); return true; })); // Execute a job :) $service->executeJob('test', array(), $worker); // Do we have the events ? $this->assertTrue($startingFlag); $this->assertTrue($executedFlag); }
public function createAction(Request $request) { $recipe = new Recipe(); $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $listener = $this->container->get('my_recipes.recipes_listener'); $dispatcher->addListener('recipe.create', array($listener, 'onRecipeCreate')); $em = $this->getDoctrine()->getManager(); $em->persist($recipe); $form = $this->createForm(new RecipeType(), $recipe); $form->handleRequest($request); if ($form->isValid()) { $em->flush(); $this->get('event_dispatcher')->dispatch('recipe.create', new RecipeEvent($recipe)); return $this->redirect($this->generateUrl('recipe_show', array('id' => $recipe->getId()))); } //# http://brentertainment.com/other/docs/cookbook/form/twig_form_customization.html#cookbook-form-twig-two-methods return $this->render("MyRecipesBundle:Recipe:form.html.twig", array("form" => $form->createView())); }
/** * @dataProvider post_auth_data */ public function test_post_auth($auth_data, $event_data, $expected_result_data) { // Modify auth $this->auth->expects($this->any())->method('acl_get')->with($this->stringContains('_'), $this->anything())->will($this->returnValueMap($auth_data)); // fetch listener $listener = $this->get_listener(); // Create Events $event = new \Symfony\Component\EventDispatcher\GenericEvent(null, $event_data); $expected_result = new \Symfony\Component\EventDispatcher\GenericEvent(null, $expected_result_data); // Dispatch $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $dispatcher->addListener('gn36.def_listen', array($listener, 'post_auth')); $dispatcher->dispatch('gn36.def_listen', $event); // Modify expected result event to mimic correct dispatch data $expected_result->setDispatcher($dispatcher); $expected_result->setName('gn36.def_listen'); // Check $this->assertEquals($expected_result, $event); }
/** * @return \Symfony\Component\EventDispatcher\EventDispatcher */ public function createEventDispatcher() { $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $dispatcher->addListener('hook_civicrm_post::Activity', array('\\Civi\\CCase\\Events', 'fireCaseChange')); $dispatcher->addListener('hook_civicrm_post::Case', array('\\Civi\\CCase\\Events', 'fireCaseChange')); $dispatcher->addListener('hook_civicrm_caseChange', array('\\Civi\\CCase\\Events', 'delegateToXmlListeners')); $dispatcher->addListener('hook_civicrm_caseChange', array('\\Civi\\CCase\\SequenceListener', 'onCaseChange_static')); $dispatcher->addListener('DAO::post-insert', array('\\CRM_Core_BAO_RecurringEntity', 'triggerInsert')); $dispatcher->addListener('DAO::post-update', array('\\CRM_Core_BAO_RecurringEntity', 'triggerUpdate')); $dispatcher->addListener('DAO::post-delete', array('\\CRM_Core_BAO_RecurringEntity', 'triggerDelete')); $dispatcher->addListener('hook_civicrm_unhandled_exception', array('CRM_Core_LegacyErrorHandler', 'handleException')); return $dispatcher; }
/** * validate that we can interact with the visit process using an eventlistener * * @return void */ public function testThrowsEvent() { $query = 'eq(name,replaceme)&limit(10)'; $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $dispatcher->addListener('rql.visit.node', [new \Graviton\Rql\Listener\TestListener(), 'onVisitNode']); $visitor = new MongoOdm(); $visitor->setBuilder($this->builder); $visitor->setDispatcher($dispatcher); $results = $this->runTestQuery($query, $visitor); $this->assertCount(1, $results); $this->assertEquals('My First Sprocket', $results[0]->name); }
/** * Test the setup * * @dataProvider setup_data */ public function test_setup($user_id, $is_reg, $is_bot, $pull_time, $expected, $last_n, $time_n) { $this->user->data['user_id'] = $user_id; $this->user->data['is_registered'] = $is_reg; $this->user->data['is_bot'] = $is_bot; $this->config['notification_pull_time'] = $pull_time; $this->config['enable_mod_rewrite'] = false; $this->config['cookie_domain'] = 'localhost'; $this->config['cookie_name'] = 'phpbb3_asd_obj'; $this->config['cookie_path'] = '/'; $this->set_listener(); if ($expected > 0) { $this->template->expects($this->exactly($expected))->method('assign_vars')->with(array('ACTIVE_NOTIFICATION_LAST' => $last_n, 'ACTIVE_NOTIFICATION_TIME' => $time_n, 'ACTIVE_NOTIFICATION_URL' => false, 'ACTIVE_NOTIFICATIONS_COOKIE_DOMAIN' => 'localhost', 'ACTIVE_NOTIFICATIONS_COOKIE_NAME' => 'phpbb3_asd_obj_an', 'ACTIVE_NOTIFICATIONS_COOKIE_PATH' => '/')); } else { $this->template->expects($this->exactly(0))->method('assign_vars'); } $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $dispatcher->addListener('core.page_header', array($this->listener, 'setup')); $dispatcher->dispatch('core.page_header'); }
throw new ErrorException($errstr, 0, $errno, $errfile, $errline); } set_error_handler("exception_error_handler"); $app = new Silex\Application(); $app->register(new Silex\Provider\ValidatorServiceProvider()); $eventDispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $ircConnection = new \Whisnet\IrcBotBundle\Connection\Socket('irc.freenode.net', 6667, $app['validator'], $eventDispatcher); $commandPrefix = '!bot'; $user = array('username' => 'thebot|' . rand(55, 950), 'mode' => '8', 'realname' => 'mana-bot'); $channels = array('#magento-de', '#magento-offtopic-de', '#magento-dev'); $listener['whisnet_irc_bot.command_PING'] = array(new \Whisnet\IrcBotBundle\EventListener\Irc\Messages\PingListener($ircConnection, $eventDispatcher), 'onData'); $listener['whisnet_irc_bot.irc_command_PRIVMSG'] = array(new \Whisnet\IrcBotBundle\EventListener\Irc\Messages\PrivMsgListener($ircConnection, $eventDispatcher, $commandPrefix), 'onData'); $listener['whisnet_irc_bot.data_from_server'] = array(new \Whisnet\IrcBotBundle\EventListener\Irc\ServerRequestListener($ircConnection, $eventDispatcher), 'onData'); #= '\Whisnet\IrcBotBundle\EventListener\Irc\ServerRequestListener'; foreach ($listener as $eventName => $eventHandler) { $eventDispatcher->addListener($eventName, $eventHandler, 10); } unset($listener); $loadUserCoreListener = new Whisnet\IrcBotBundle\EventListener\Plugins\Core\LoadUserCoreListener($ircConnection); $loadUserCoreListener->setConfig($user, $channels); $listener['whisnet_irc_bot.post_connection'] = array($loadUserCoreListener, 'onCore'); $listener['whisnet_irc_bot.bot_command_join'] = array(new \Whisnet\IrcBotBundle\EventListener\Plugins\Commands\JoinCommandListener($ircConnection), 'onCommand'); $listener['whisnet_irc_bot.bot_command_part'] = array(new \Whisnet\IrcBotBundle\EventListener\Plugins\Commands\PartCommandListener($ircConnection), 'onCommand'); /* $listener['whisnet_irc_bot.bot_command_quit'] = array(new \Whisnet\IrcBotBundle\EventListener\Plugins\Commands\QuitCommandListener($ircConnection),'onCommand'); */ $listener['whisnet_irc_bot.bot_command_info'] = array(new \Whisnet\IrcBotBundle\EventListener\Plugins\Commands\InfoCommandListener($ircConnection), 'onCommand'); $listener['whisnet_irc_bot.bot_command_datetime'] = array(new \Whisnet\IrcBotBundle\EventListener\Plugins\Commands\DateTimeCommandListener($ircConnection), 'onCommand'); $seenCommandListener = new \Whisnet\IrcBotBundle\EventListener\Plugins\Commands\SeenCommandListener($ircConnection); $seenCommandListener->setCacheDir(__DIR__ . '/cache');
/** * Test events * * @dataProvider gallery_link_in_profile_data * profile_fileds * get_user_ids */ public function test_gallery_link_events($option, $user_id, $expect) { $this->config['phpbb_gallery_profile_pega'] = $option; $user_ids = array($user_id); $event_data = array('user_ids'); $event_one = new \phpbb\event\data(compact($event_data)); $profile_row = array(); $event_two_data = array('profile_row'); $event_two = new \phpbb\event\data(compact($event_two_data)); $this->set_listener(); $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $dispatcher->addListener('core.grab_profile_fields_data', array($this->listener, 'get_user_ids')); $dispatcher->addListener('core.generate_profile_fields_template_data_before', array($this->listener, 'profile_fileds')); $dispatcher->dispatch('core.grab_profile_fields_data', $event_one); $dispatcher->dispatch('core.generate_profile_fields_template_data_before', $event_two); $ouput = $event_two->get_data_filtered($event_two_data); $expacted = array('phpbb_gallery' => array('value' => array('album_id' => 1), 'data' => array('field_id' => '', 'lang_id' => '', 'lang_name' => 'GALLERY', 'lang_explain' => '', 'lang_default_value' => '', 'field_name' => 'phpbb_gallery', 'field_type' => 'profilefields.type.url', 'field_ident' => 'phpbb_gallery', 'field_length' => '40', 'field_minlen' => '12', 'field_maxlen' => '255', 'field_novalue' => '', 'field_default_value' => '', 'field_validation' => '', 'field_required' => '0', 'field_show_on_reg' => '0', 'field_hide' => '0', 'field_no_view' => '0', 'field_active' => '1', 'field_order' => '', 'field_show_profile' => '1', 'field_show_on_vt' => '1', 'field_show_novalue' => '0', 'field_show_on_pm' => '1', 'field_show_on_ml' => '1', 'field_is_contact' => '1', 'field_contact_desc' => 'VISIT_GALLERY', 'field_contact_url' => '%s'))); if ($expect) { $this->assertEquals($expacted, $ouput['profile_row']); } else { $this->assertEmpty($ouput['profile_row']); } }
* @package doctrine-dbal * @license LGPL * @filesource */ /** @var Pimple $container */ $container['event-dispatcher'] = $container->share(function () { $eventDispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); if (isset($GLOBALS['TL_EVENTS']) && is_array($GLOBALS['TL_EVENTS'])) { foreach ($GLOBALS['TL_EVENTS'] as $eventName => $listeners) { foreach ($listeners as $listener) { if (is_array($listener) && count($listener) === 2 && is_int($listener[1])) { list($listener, $priority) = $listener; } else { $priority = 0; } $eventDispatcher->addListener($eventName, $listener, $priority); } } } if (isset($GLOBALS['TL_EVENT_SUBSCRIBERS']) && is_array($GLOBALS['TL_EVENT_SUBSCRIBERS'])) { foreach ($GLOBALS['TL_EVENT_SUBSCRIBERS'] as $eventSubscriber) { if (!is_object($eventSubscriber)) { if (is_callable($eventSubscriber)) { $eventSubscriber = call_user_func($eventSubscriber, $eventDispatcher); } else { $eventSubscriber = new $eventSubscriber(); } } $eventDispatcher->addSubscriber($eventSubscriber); } }
/** * @see EventDispatcherInterface::addListener() * * @api */ public static function addListener($eventName, $listener, $priority = 0) { return static::$instance->addListener($eventName, $listener, $priority); }
require __DIR__ . '/config.php'; require __DIR__ . '/vendor/autoload.php'; function exception_error_handler($errno, $errstr, $errfile, $errline) { throw new ErrorException($errstr, 0, $errno, $errfile, $errline); } set_error_handler("exception_error_handler"); $app = new Silex\Application(); $app->register(new Silex\Provider\ValidatorServiceProvider()); $eventDispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $ircConnection = new \Whisnet\IrcBotBundle\Connection\Socket($serverUrl, $serverPort, $app['validator'], $eventDispatcher); $listener['whisnet_irc_bot.command_PING'] = array(new \Whisnet\IrcBotBundle\EventListener\Irc\Messages\PingListener($ircConnection, $eventDispatcher), 'onData'); $listener['whisnet_irc_bot.irc_command_PRIVMSG'] = array(new \Whisnet\IrcBotBundle\EventListener\Irc\Messages\PrivMsgListener($ircConnection, $eventDispatcher, $commandPrefix), 'onData'); $listener['whisnet_irc_bot.data_from_server'] = array(new \Whisnet\IrcBotBundle\EventListener\Irc\ServerRequestListener($ircConnection, $eventDispatcher), 'onData'); foreach ($listener as $eventName => $eventHandler) { $eventDispatcher->addListener($eventName, $eventHandler, 10); } unset($listener); $loadUserCoreListener = new Whisnet\IrcBotBundle\EventListener\Plugins\Core\LoadUserCoreListener($ircConnection); $loadUserCoreListener->setConfig($user, $channels); $listener['whisnet_irc_bot.post_connection'] = array($loadUserCoreListener, 'onCore'); $helpList = new SplDoublyLinkedList(); foreach ($botCommands as $commandType => $commands) { foreach ($commands as $command => $commandData) { if (!$commandData['isActive']) { continue; } if (array_key_exists('classFile', $commandData)) { $classfilepath = $commandData['classFile']; if (!file_exists($classfilepath)) { die($classfilepath . ' not found');