Beispiel #1
0
 public function case_open_with_context()
 {
     $self = $this;
     $this->given($this->mockGenerator->orphanize('__construct'), $server = new \Mock\Hoa\Socket\Server(), $streamName = 'foobar', $context = Stream\Context::getInstance('foo'), $flag = SUT::BIND | SUT::LISTEN, $oldMasters = $this->invoke($server)->getMasters(), $oldServers = $this->invoke($server)->getServers(), $oldStack = $this->invoke($server)->getStack(), $this->calling($server)->getFlag = $flag, $this->function->stream_socket_server = function ($_streamName, &$_errno, &$_errstr, $_flag, $_context) use($self, &$called, $streamName, $flag, $context) {
         $called = true;
         $self->string($_streamName)->isEqualTo($streamName)->integer($_flag)->isEqualTo($flag)->resource($_context)->isStreamContext()->isIdenticalTo($context->getContext());
         return fopen(__FILE__, 'r');
     })->when($result = $this->invoke($server)->_open($streamName, $context))->then->resource($result)->let($masters = $this->invoke($server)->getMasters())->integer(count($masters))->isEqualTo(count($oldMasters) + 1)->isEqualTo(1)->array($masters)->resource($masters[0])->isIdenticalTo($result)->let($servers = $this->invoke($server)->getServers())->integer(count($servers))->isEqualTo(count($oldServers) + 1)->isEqualTo(1)->array($servers)->object($servers[0])->isIdenticalTo($server)->let($stack = $this->invoke($server)->getStack())->integer(count($stack))->isEqualTo(count($oldStack) + 1)->isEqualTo(1)->array($stack)->resource($stack[0])->isIdenticalTo($result);
 }
Beispiel #2
0
 /**
  * Create a directory.
  *
  * @param   string  $name       Directory name.
  * @param   string  $mode       Create mode. Please, see the self::MODE_CREATE*
  *                              constants.
  * @param   string  $context    Context ID (please, see the
  *                              \Hoa\Stream\Context class).
  * @return  bool
  * @throws  \Hoa\File\Exception
  */
 public static function create($name, $mode = self::MODE_CREATE_RECURSIVE, $context = null)
 {
     if (true === is_dir($name)) {
         return true;
     }
     if (empty($name)) {
         return false;
     }
     if (null !== $context) {
         if (false === Stream\Context::contextExists($context)) {
             throw new Exception('Context %s was not previously declared, cannot retrieve ' . 'this context.', 2, $context);
         } else {
             $context = Stream\Context::getInstance($context);
         }
     }
     if (null === $context) {
         return @mkdir($name, 0755, self::MODE_CREATE_RECURSIVE === $mode);
     }
     return @mkdir($name, 0755, self::MODE_CREATE_RECURSIVE === $mode, $context->getContext());
 }
Beispiel #3
0
 /**
  * Open the stream.
  *
  * @return  \Hoa\Stream
  * @throws  \Hoa\Stream\Exception
  */
 public final function open()
 {
     $context = $this->_context;
     if (true === $this->_hasBeenDiffered) {
         if (null === $context) {
             $handle = Context::getInstance(uniqid());
             $handle->setParameters(['notification' => [$this, '_notify']]);
             $context = $handle->getId();
         } elseif (true === Context::contextExists($context)) {
             $handle = Context::getInstance($context);
             $parameters = $handle->getParameters();
             if (!isset($parameters['notification'])) {
                 $handle->setParameters(['notification' => [$this, '_notify']]);
             }
         }
     }
     $this->_bucket = self::_getStream($this->_streamName, $this, $context);
     return $this;
 }
Beispiel #4
0
 public function case_open_with_context()
 {
     $self = $this;
     $this->given($this->mockGenerator->orphanize('__construct'), $client = new \Mock\Hoa\Socket\Client(), $streamName = 'foobar', $context = Stream\Context::getInstance('foo'), $timeout = 42, $flag = SUT::CONNECT, $oldStack = $this->invoke($client)->getStack(), $oldNodes = $client->getNodes(), $this->calling($client)->getTimeout = $timeout, $this->calling($client)->getFlag = $flag, $this->function->stream_socket_client = function ($_streamName, &$_errno, &$_errstr, $_timeout, $_flag, $_context) use($self, &$called, $streamName, $timeout, $flag, $context) {
         $called = true;
         $self->string($_streamName)->isEqualTo($streamName)->integer($_timeout)->isEqualTo($timeout)->integer($_flag)->isEqualTo($flag)->resource($_context)->isStreamContext()->isIdenticalTo($context->getContext());
         return fopen(__FILE__, 'r');
     })->when($result = $this->invoke($client)->_open($streamName, $context))->then->resource($result)->let($stack = $this->invoke($client)->getStack())->integer(count($stack))->isEqualTo(count($oldStack) + 1)->isEqualTo(1)->array($stack)->resource($stack[0])->isIdenticalTo($result)->let($node = $client->getCurrentNode())->object($node)->isInstanceOf('Hoa\\Socket\\Node')->string($node->getId())->isEqualTo($this->invoke($client)->getNodeId($result))->resource($node->getSocket())->isIdenticalTo($result)->object($node->getConnection())->isIdenticalTo($client)->let($nodes = $client->getNodes())->integer(count($nodes))->isEqualTo(count($oldNodes) + 1)->array($nodes)->object($nodes[$node->getId()])->isIdenticalTo($node);
 }