public function testGenerateReadInt32IntoVariableStatement() { $context = $this->createMessagesContext([1 => ['count', Field::TYPE_INT32, Field::LABEL_REQUIRED]]); $generator = new ReadFieldStatementGenerator($context); $entity = $context->getEntity($this->messageClass); $descritor = $entity->getDescriptor(); $field = $descritor->getFieldList()[0]; $generator->setTargetVar('$count'); $generator->setBreakMode(ReadFieldStatementGenerator::BREAK_MODE_RETURN); $actual = $generator->generateFieldReadStatement($entity, $field); $expected = <<<'CODE' \Protobuf\WireFormat::assertWireType($wire, 5); $count = $reader->readVarint($stream); return $count; CODE; $this->assertEquals($expected, implode(PHP_EOL, $actual)); }
/** * @param \Protobuf\Compiler\Entity $entity * @param \google\protobuf\FieldDescriptorProto $field * * @return string[] */ protected function generateFieldReadStatement(Entity $entity, FieldDescriptorProto $field) { $generator = new ReadFieldStatementGenerator($this->context); $generator->setBreakMode(ReadFieldStatementGenerator::BREAK_MODE_RETURN); $generator->setTargetVar('$value'); return $generator->generateFieldReadStatement($entity, $field); }