public function dataTransferred()
 {
     $out = new MemoryOutputStream();
     $s = new StreamTransfer(new MemoryInputStream('Hello'), $out);
     $s->transferAll();
     $this->assertEquals('Hello', $out->getBytes());
 }
 public function multipeWrites()
 {
     $out = new MemoryOutputStream();
     $stream = new Base64OutputStream($out);
     $stream->write('Hello');
     $stream->write(' ');
     $stream->write('World');
     $stream->close();
     $this->assertEquals(base64_encode('Hello World'), $out->getBytes());
 }
 /**
  * Helper which runs the compiler
  *
  * @param  string[] $args
  * @return [:var]
  */
 protected function run($args = [])
 {
     $saved = ['out' => Console::$out->getStream(), 'err' => Console::$err->getStream()];
     Console::$out->setStream($out = new MemoryOutputStream());
     Console::$err->setStream($err = new MemoryOutputStream());
     try {
         $exit = Runner::main($args);
         return ['exit' => $exit, 'out' => $out->getBytes(), 'err' => $err->getBytes()];
     } finally {
         Console::$out->setStream($saved['out']);
         Console::$err->setStream($saved['err']);
     }
 }
Exemple #4
0
 /**
  * Asserts a given output stream contains the given bytes       
  *
  * @param   io.streams.MemoryOutputStream m
  * @param   string bytes
  * @throws  unittest.AssertionFailedError
  */
 protected function assertOnStream(MemoryOutputStream $m, $bytes, $message = 'Not contained')
 {
     strstr($m->getBytes(), $bytes) || $this->fail($message, $m->getBytes(), $bytes);
 }
 public function write()
 {
     $s = new MemoryOutputStream();
     $this->image->saveTo(new GifStreamWriter($s));
     $this->assertNotEquals('', $s->getBytes());
 }
 public function equalsSign()
 {
     $out = new MemoryOutputStream();
     $stream = new QuotedPrintableOutputStream($out);
     $stream->write('A=1');
     $stream->close();
     $this->assertEquals('A=3D1', $out->getBytes());
 }
 public function writeLinef()
 {
     $stream = new StringWriter($out = new MemoryOutputStream());
     $stream->writeLinef('This %s the %d line', 'is', 1);
     $this->assertEquals("This is the 1 line\n", $out->getBytes());
 }
Exemple #8
0
 public function writing_to_stream()
 {
     $out = new MemoryOutputStream();
     Sequence::of([1, 2, 3, 4])->each([$out, 'write']);
     $this->assertEquals('1234', $out->getBytes());
 }
Exemple #9
0
 /**
  * Send a frame to server
  *
  * This is a low-level protocol function.
  *
  * @param   peer.stomp.frame.Frame frame
  * @return  peer.stomp.Frame or null
  */
 public function sendFrame(Frame $frame)
 {
     // Trace
     if ($this->cat) {
         $mo = new MemoryOutputStream();
         $frame->write(new StringWriter($mo));
         $this->debug('>>>', $mo->getBytes());
     }
     $frame->write($this->out);
     if ($frame->requiresImmediateResponse()) {
         return $this->recvFrame();
     }
     return null;
 }