Example #1
0
 public function case_send()
 {
     $self = $this;
     $this->given($eventId = 'hoa://Event/Test', $source = new \Mock\Hoa\Event\Source(), LUT::register($eventId, $source), $bucket = new SUT('foo'), LUT::getEvent($eventId)->attach(function (SUT $receivedBucket) use($self, $bucket, &$called) {
         $called = true;
         $self->object($receivedBucket)->isIdenticalTo($bucket);
     }))->when($result = $bucket->send($eventId, $source))->then->variable($result)->isNull()->boolean($called)->isTrue();
 }
Example #2
0
 /**
  * Create an exception.
  * An exception is built with a formatted message, a code (an ID), and an
  * array that contains the list of formatted string for the message. If
  * chaining, we can add a previous exception.
  *
  * @param   string      $message      Formatted message.
  * @param   int         $code         Code (the ID).
  * @param   array       $arguments    Arguments to format message.
  * @param   \Throwable  $previous     Previous exception in chaining.
  * @return  void
  */
 public function __construct($message, $code = 0, $arguments = [], $previous = null)
 {
     parent::__construct($message, $code, $arguments, $previous);
     if (false === Event::eventExists('hoa://Event/Exception')) {
         Event::register('hoa://Event/Exception', __CLASS__);
     }
     $this->send();
     return;
 }
Example #3
0
 /**
  * Get a stream in the register.
  * If the stream does not exist, try to open it by calling the
  * $handler->_open() method.
  *
  * @param   string       $streamName    Stream name.
  * @param   \Hoa\Stream  $handler       Stream handler.
  * @param   string       $context       Context ID (please, see the
  *                                      \Hoa\Stream\Context class).
  * @return  array
  * @throws  \Hoa\Stream\Exception
  */
 private static final function &_getStream($streamName, Stream $handler, $context = null)
 {
     $name = md5($streamName);
     if (null !== $context) {
         if (false === Context::contextExists($context)) {
             throw new Exception('Context %s was not previously declared, cannot retrieve ' . 'this context.', 0, $context);
         }
         $context = Context::getInstance($context);
     }
     if (!isset(self::$_register[$name])) {
         self::$_register[$name] = [self::NAME => $streamName, self::HANDLER => $handler, self::RESOURCE => $handler->_open($streamName, $context), self::CONTEXT => $context];
         Event::register('hoa://Event/Stream/' . $streamName, $handler);
         // Add :open-ready?
         Event::register('hoa://Event/Stream/' . $streamName . ':close-before', $handler);
     } else {
         $handler->_borrowed = true;
     }
     if (null === self::$_register[$name][self::RESOURCE]) {
         self::$_register[$name][self::RESOURCE] = $handler->_open($streamName, $context);
     }
     return self::$_register[$name];
 }