/** * Register the reporters. * * @return $this */ public function register() { $this->eventEmitter->on('peridot.start', [$this, 'onPeridotStart']); $this->eventEmitter->on('peridot.execute', [$this, 'onPeridotExecute']); $this->eventEmitter->on('peridot.reporters', [$this, 'onPeridotReporters']); return $this; }
public function setEventEmitter(EventEmitterInterface $emitter) { $emitter->on('phantestic.test.failresult', [$this, 'handleFail']); $emitter->on('phantestic.test.passresult', [$this, 'handlePass']); $emitter->on('phantestic.tests.before', [$this, 'beforeTests']); $emitter->on('phantestic.tests.after', [$this, 'afterTests']); }
public function __construct(EventEmitterInterface $stream) { $this->lines = new \SplQueue(); $this->promisedLines = new \SplQueue(); $stream->on('data', function ($data) { $newline_count = substr_count($data, "\n"); $this->buf .= $data; if ($newline_count > 0) { $lines = explode("\n", $this->buf); $this->buf = array_pop($lines); foreach ($lines as $line) { $line .= "\n"; if ($this->onLine) { $onLine = $this->onLine; $onLine($line); } if ($this->promisedLines->count() > 0) { $this->promisedLines->dequeue()->resolve($line); } else { $this->lines->enqueue($line); } } } }); }
public function inherit(array $events, BaseEmitterInterface $emitter) { foreach ($events as $event) { $emitter->on($event, function () use($event) { $this->emit($event, func_get_args()); }); } }
static function forwardEvents(EventEmitterInterface $to, EventEmitterInterface $from, array $events) { foreach ($events as $event) { $from->on($event, function () use($event, $to) { $event_args = func_get_args(); call_user_func_array(array($to, 'emit'), array($event, $event_args)); }); } }
/** * Register the Yo plugin * * @param EventEmitterInterface $emitter * @param $token * @param array $users * @param null $link * @return static */ public static function register(EventEmitterInterface $emitter, $token, array $users, $link = null) { $request = new Request($token, $users); if (!is_null($link)) { $request->setLink($link); } $plugin = new static($request); $emitter->on('peridot.end', [$plugin, 'onPeridotEnd']); return $plugin; }
/** * * @param EventEmitterInterface $emitter * @param string[] $events * @param callable $callback * @return callable[] */ protected static function registerCallbacks(EventEmitterInterface $emitter, array $events, callable $callback) { if (empty($events)) { return []; } $wrappedCallback = function () use($callback) { return $callback(func_get_args()); }; $listeners = array_fill_keys($events, $wrappedCallback); foreach ($listeners as $event => $callback) { $emitter->on($event, $callback); } return $listeners; }
/** * @param EventEmitterInterface $emitter */ public function __construct(EventEmitterInterface $emitter) { $this->emitter = $emitter; $this->emitter->on('peridot.start', [$this, 'onPeridotStart']); $this->emitter->on('peridot.execute', [$this, 'onPeridotExecute']); $this->emitter->on('peridot.load', [$this, 'onPeridotLoad']); $this->emitter->on('peridot.configure', [$this, 'onPeridotConfigure']); $this->emitter->on('peridot.reporters', [$this, 'onPeridotReporters']); }
/** * Tests a successful feed poll with no new items. */ public function testSuccessfulFeedPollWithNoNewItems() { // Simulate the Http plugin response for the first poll $feed = $this->getFeed(); $feedString = $this->getFeedString($feed); $this->emitter->on('http.request', function ($request) use($feedString) { $request->callResolve($feedString, array(), 200); }); // Invoke the first poll $this->plugin->setLoop($this->loop); $this->plugin->setEventQueue($this->event, $this->queue); Phake::inOrder(Phake::verify($this->logger)->info('Sending request for feed URL', array('url' => $this->url)), Phake::verify($this->logger)->info('Processing feed', array('url' => $this->url)), Phake::verify($this->logger)->debug('Received feed data', array('data' => $feedString))); // Verify the next poll is queued Phake::verify($this->loop)->addTimer(300, Phake::capture($callback)); // Invoke the next poll $callback(); // Verify no items are sent because the feed hasn't been updated Phake::verify($this->queue, Phake::times(0))->ircPrivmsg(Phake::anyParameters()); }
public function registerTo(EventEmitterInterface $emitter) { $emitter->on(self::START_EVENT, [$this, 'onStart']); $emitter->on(self::SUITE_START_EVENT, [$this, 'onSuiteStart']); }
/** * Listen for message events. * * @param EventEmitterInterface $emitter * @return void */ protected function listen(EventEmitterInterface $emitter) { $emitter->on('suite.start', [$this, 'onSuiteStart']); $emitter->on('suite.end', [$this, 'onSuiteEnd']); $emitter->on('test.passed', [$this, 'onTestPassed']); $emitter->on('test.failed', [$this, 'onTestFailed']); $emitter->on('test.pending', [$this, 'onTestPending']); $emitter->on('suite.halt', [$this, 'onSuiteHalt']); }
/** * @param EventEmitterInterface $emitter */ public function __construct(EventEmitterInterface $emitter) { $this->emitter = $emitter; $this->emitter->on('peridot.reporters', [$this, 'onPeridotReporters']); }
/** * Creates a `Promise` which resolves with an array of all the event data * * @param ReadableStreamInterface|WritableStreamInterface $stream * @param string $event * @return CancellablePromiseInterface Promise<string, Exception> */ function all(EventEmitterInterface $stream, $event = 'data') { // stream already ended => resolve with empty buffer if ($stream instanceof ReadableStreamInterface) { // readable or duplex stream not readable => already closed // a half-open duplex stream is considered closed if its readable side is closed if (!$stream->isReadable()) { return Promise\resolve(array()); } } elseif ($stream instanceof WritableStreamInterface) { // writable-only stream (not duplex) not writable => already closed if (!$stream->isWritable()) { return Promise\resolve(array()); } } $buffer = array(); $bufferer = function ($data) use(&$buffer) { $buffer[] = $data; }; $stream->on($event, $bufferer); $promise = new Promise\Promise(function ($resolve, $reject) use($stream, &$buffer) { $stream->on('error', function ($error) use($reject) { $reject(new \RuntimeException('An error occured on the underlying stream while buffering', 0, $error)); }); $stream->on('close', function () use($resolve, &$buffer) { $resolve($buffer); }); }, function ($_, $reject) { $reject(new \RuntimeException('Cancelled buffering')); }); return $promise->then(null, function ($error) use(&$buffer, $bufferer, $stream, $event) { // promise rejected => clear buffer and buffering $buffer = array(); $stream->removeListener($event, $bufferer); throw $error; }); }
/** * Registers the given listener for the given event. * * @param string $event Must be one of state machine's $supported_events, hence one of the ON_* constants. * @param callable $listener * * @throws Error If the given event is not supported. */ public function on($event, callable $listener) { $this->guardSupportedEvents($event); $this->event_emitter->on($event, $listener); }
/** * Constructor. * * @param EventEmitterInterface $eventEmitter */ public function __construct(EventEmitterInterface $eventEmitter) { $eventEmitter->on('code-coverage.start', [$this, 'onCodeCoverageStart']); }
/** * Attach the necessary events for this plugin to work. */ public function listen() { $this->emitter->on('suite.start', [$this, 'onSuiteStart']); }
/** * Attach the plugin. */ public function attach(EventEmitterInterface $emitter) { $emitter->on('suite.define', [$this, 'onSuiteDefine']); $emitter->on('suite.start', [$this, 'onSuiteStart']); }
/** * @param EventEmitterInterface $emitter * @param HttpKernelInterface|callable $factory */ public static function register(EventEmitterInterface $emitter, $factory, $property = "client") { $plugin = new static($emitter, $factory, $property); $emitter->on('runner.start', [$plugin, 'onRunnerStart']); return $plugin; }
/** * Listen for Peridot events */ private function listen() { $this->emitter->on('peridot.configure', [$this, 'onPeridotConfigure']); $this->emitter->on('peridot.start', [$this, 'onPeridotStart']); $this->emitter->on('peridot.end', [$this, 'onPeridotEnd']); }
/** * Listen for Peridot events. */ private function listen() { $this->eventEmitter->on('suite.start', [$this, 'onSuiteStart']); }