Example #1
0
 /**
  * @inheritdoc
  */
 public function restoreWithoutProxyMarker($a)
 {
     if (is_object($a)) {
         if ($this->isTransferObject($a)) {
             $r = new \ReflectionClass($a);
             foreach ($r->getProperties() as $prop) {
                 $prop->setAccessible(true);
                 $pval = $prop->getValue($a);
                 if ($pval instanceof Marker) {
                     $pval = $this->refPool->getObj($pval->getRef());
                 } else {
                     $pval = $this->restoreWithoutProxyMarker($pval);
                 }
                 $prop->setValue($a, $pval);
             }
         }
     } else {
         if (is_array($a)) {
             foreach ($a as &$val) {
                 $val = $this->restoreWithoutProxyMarker($val);
             }
         }
     }
     return $a;
 }
Example #2
0
 public function testRefPool()
 {
     $pool = new RefPool();
     $a = new \stdClass();
     $a->val = 'a';
     $b = new \stdClass();
     $b->val = 'b';
     $aref = $pool->pushRef($a);
     $bref = $pool->pushRef($b);
     $bref2 = $pool->pushRef($b);
     $this->assertEquals($bref, $bref2);
     $this->assertNotEquals($aref, $bref);
     $this->assertEquals($a, $pool->getObj($aref));
     $this->assertEquals($b, $pool->getObj($bref));
     $this->assertTrue($pool->exists($aref));
     $this->assertFalse($pool->exists(99999));
     $this->assertNotEquals($pool->pushRef(new \stdClass()), $pool->pushRef(new \stdClass()));
 }
Example #3
0
 public function testRun()
 {
     $this->transport->setRing(false);
     $s = m::mock('stdClass');
     $s->shouldReceive('foo')->withNoArgs()->andReturn('foobar');
     $ref = $this->refpool->pushRef($s);
     $this->transport->setBuffer([C::REF => $ref, C::CMD => C::CALL, C::NAME => 'foo', C::ARGS => []]);
     $this->host->run();
     $this->assertEquals([C::CMD => C::CRETURN, C::SCALAR => 'foobar'], $this->transport->getBuffer());
     $this->transport->setBuffer([C::REF => $ref, C::CMD => C::CRETURN, C::CLASSNAME => 'stdClass', C::ARGS => []]);
     $proxy = $this->host->run();
     $this->assertEquals(self::MAGIC, $proxy);
     $this->transport->setBuffer([C::CMD => C::CRETURN, C::SCALAR => 5]);
     $val = $this->host->run();
     $this->assertEquals(5, $val);
     $this->transport->setBuffer([C::CMD => C::CRETURN, C::SCALAR => null]);
     $val = $this->host->run();
     $this->assertNull($val);
 }