/** * @inheritdoc */ public function insertProxyMarker($a) { if (is_object($a)) { if (!$this->isTransferObject($a)) { $ref = $this->refPool->pushRef($a); $a = new Marker($ref, get_class($a)); } else { // look for objects in transferobject properties $r = new \ReflectionClass($a); foreach ($r->getProperties() as $prop) { $prop->setAccessible(true); $pval = $prop->getValue($a); if (!is_scalar($pval)) { $pval = $this->insertProxyMarker($pval); $prop->setValue($a, $pval); } } } } else { if (is_array($a)) { foreach ($a as &$val) { $val = $this->insertProxyMarker($val); } } } return $a; }
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())); }
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); }