public assemble ( Phpro\SoapClient\CodeGenerator\Context\ContextInterface $context ) | ||
$context | Phpro\SoapClient\CodeGenerator\Context\ContextInterface |
public function assemble(ContextInterface $context)
{
$class = $context->getClass();
$properties = $context->getType()->getProperties();
$firstProperty = count($properties) ? current($properties) : null;
try {
$interfaceAssembler = new InterfaceAssembler(\IteratorAggregate::class);
if ($interfaceAssembler->canAssemble($context)) {
$interfaceAssembler->assemble($context);
}
if ($firstProperty) {
$this->implementGetIterator($class, $firstProperty);
}
} catch (\Exception $e) {
throw AssemblerException::fromException($e);
}
}
/** * @test */ function it_assembles_a_type() { $assembler = new IteratorAssembler(); $context = $this->createContext(); $assembler->assemble($context); $code = $context->getClass()->generate(); $expected = <<<CODE namespace MyNamespace; use IteratorAggregate; class MyType implements IteratorAggregate { /** * @return \\ArrayIterator */ public function getIterator() { return new \\ArrayIterator(is_array(\$this->prop1) ? \$this->prop1 : []); } } CODE; $this->assertEquals($expected, $code); }