public function testStreamSetterWrapsValue()
 {
     $simple1 = new Simple();
     $simple2 = new Simple();
     $handle = fopen('php://temp', 'w+');
     fwrite($handle, 'foo');
     $simple1->setBytes("bar");
     $simple2->setBytes($handle);
     $this->assertInstanceOf('Protobuf\\Stream', $simple1->getBytes());
     $this->assertInstanceOf('Protobuf\\Stream', $simple2->getBytes());
     $this->assertEquals('bar', (string) $simple1->getBytes());
     $this->assertEquals('foo', (string) $simple2->getBytes());
 }
 public function testSimpleSerializedSize()
 {
     $simple = new Simple();
     $calculator = $this->getMock(SizeCalculator::CLASS, [], [], '', false);
     $context = $this->getMock(ComputeSizeContext::CLASS, [], [], '', false);
     $simple->setBool(true);
     $simple->setBytes("bar");
     $simple->setString("foo");
     $simple->setFloat(12345.123);
     $simple->setUint32(123456789);
     $simple->setInt32(-123456789);
     $simple->setFixed32(123456789);
     $simple->setSint32(-123456789);
     $simple->setSfixed32(-123456789);
     $simple->setDouble(123456789.12345);
     $simple->setInt64(-123456789123456789);
     $simple->setUint64(123456789123456789);
     $simple->setFixed64(123456789123456789);
     $simple->setSint64(-123456789123456789);
     $simple->setSfixed64(-123456789123456789);
     $context->expects($this->once())->method('getSizeCalculator')->willReturn($calculator);
     $calculator->expects($this->exactly(4))->method('computeVarintSize')->will($this->returnValueMap([[-123456789123456789, 10], [123456789123456789, 9], [-123456789, 10], [123456789, 4]]));
     $calculator->expects($this->once())->method('computeStringSize')->with('foo')->willReturn(3);
     $calculator->expects($this->once())->method('computeByteStreamSize')->with('bar')->willReturn(3);
     $calculator->expects($this->once())->method('computeZigzag32Size')->with(-123456789)->willReturn(4);
     $calculator->expects($this->once())->method('computeZigzag64Size')->with(-123456789123456789)->willReturn(9);
     $simple->serializedSize($context);
 }
예제 #3
0
 /**
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage Argument 1 passed to ProtobufCompilerTest\Protos\Simple::merge must be a ProtobufCompilerTest\Protos\Simple, ProtobufCompilerTest\Protos\Person given
  */
 public function testMergeException()
 {
     $simple = new Simple();
     $person = new Person();
     $simple->merge($person);
 }
예제 #4
0
 public function testSimpleMessageClear()
 {
     $simple = new Simple();
     $simple->setBool(true);
     $simple->setString("foo");
     $simple->setFloat(12345.123);
     $simple->setUint32(123456789);
     $simple->setInt32(-123456789);
     $simple->setFixed32(123456789);
     $simple->setSint32(-123456789);
     $simple->setSfixed32(-123456789);
     $simple->setDouble(123456789.12345);
     $simple->setInt64(-123456789123456789);
     $simple->setUint64(123456789123456789);
     $simple->setFixed64(123456789123456789);
     $simple->setSint64(-123456789123456789);
     $simple->setBytes(Stream::wrap("bar"));
     $simple->setSfixed64(-123456789123456789);
     $this->assertSame(true, $simple->getBool());
     $this->assertSame("foo", $simple->getString());
     $this->assertSame(12345.123, $simple->getFloat());
     $this->assertSame(123456789, $simple->getUint32());
     $this->assertSame(-123456789, $simple->getInt32());
     $this->assertSame(123456789, $simple->getFixed32());
     $this->assertSame(-123456789, $simple->getSint32());
     $this->assertSame(-123456789, $simple->getSfixed32());
     $this->assertSame(123456789.12345, $simple->getDouble());
     $this->assertSame(-123456789123456789, $simple->getInt64());
     $this->assertSame(123456789123456789, $simple->getUint64());
     $this->assertSame(123456789123456789, $simple->getFixed64());
     $this->assertSame(-123456789123456789, $simple->getSint64());
     $this->assertSame(-123456789123456789, $simple->getSfixed64());
     $this->assertInstanceOf('Protobuf\\Stream', $simple->getBytes());
     $simple->clear();
     $this->assertNull($simple->getBool());
     $this->assertNull($simple->getString());
     $this->assertNull($simple->getFloat());
     $this->assertNull($simple->getUint32());
     $this->assertNull($simple->getInt32());
     $this->assertNull($simple->getFixed32());
     $this->assertNull($simple->getSint32());
     $this->assertNull($simple->getSfixed32());
     $this->assertNull($simple->getDouble());
     $this->assertNull($simple->getInt64());
     $this->assertNull($simple->getUint64());
     $this->assertNull($simple->getFixed64());
     $this->assertNull($simple->getSint64());
     $this->assertNull($simple->getSfixed64());
     $this->assertNull($simple->getBytes());
 }