Exemple #1
0
 public function testSaveLoad()
 {
     $zmsg = new Zmsg();
     $zmsg->body_set("Hello");
     $zmsg->wrap("address1", "");
     $zmsg->wrap("address2");
     $this->assertEquals($zmsg->parts(), 4);
     $fh = fopen(sys_get_temp_dir() . "/zmsgtest.zmsg", 'w');
     $zmsg->save($fh);
     fclose($fh);
     $fh = fopen(sys_get_temp_dir() . "/zmsgtest.zmsg", 'r');
     $zmsg2 = new Zmsg();
     $zmsg2->load($fh);
     $this->assertEquals($zmsg2->last(), $zmsg->last());
     fclose($fh);
     $this->assertEquals($zmsg2->parts(), 4);
 }
Exemple #2
0
 public function testLoggerWithContext()
 {
     $endpoint = "inproc://zmq_logger2";
     $receiver = $this->createCollector(self::$context, $endpoint);
     $log1 = new ZLogger('l3', $endpoint, self::$context);
     $this->emptyPoll($receiver);
     $collector = new Zmsg($receiver);
     $msgOut = "asd123";
     $context = [1 => 2, 'a' => 'b'];
     $log1->debug($msgOut, $context);
     $collector->recv();
     $this->assertEquals($collector->parts(), 6);
     $this->assertEquals($collector->body(), json_encode($context));
     $this->assertEquals($collector->pop(), 'l3');
     $collector->pop();
     //time
     $this->assertEquals($collector->pop(), 'debug');
     $this->assertEquals($collector->pop(), $msgOut);
     $this->assertEquals($collector->pop(), ZLogger::CONTEXT_DELIMITER);
     $this->assertEquals($collector->pop(), json_encode($context));
 }