function it_renders_statement_as_object_property_and_wraps_it_in_block(StatementInterface $objectStatement, StatementInterface $propertyStatement, ExporterInterface $export) { $objectStatement->compile($export)->willReturn('$this'); $propertyStatement->compile($export)->willReturn('$another->call'); $this->beConstructedWith($objectStatement, $propertyStatement); $this->compile($export)->shouldReturn('$this->{$another->call}'); }
/** * Compiles variable statement * * @param ExporterInterface $export * * @return string */ public function compile(ExporterInterface $export) { if ($this->name instanceof StatementInterface) { return sprintf('${%s}', $this->name->compile($export)); } return sprintf('$%s', $this->name); }
function it_generates_a_new_class_from_another_statement(ExporterInterface $export, StatementInterface $item) { $this->stubExport($export, [1, 2, 3]); $item->compile($export)->willReturn('$className'); $this->beConstructedWith($item, [1, 2, 3]); $this->compile($export)->shouldReturn('new $className(1, 2, 3)'); }
function it_renders_closure_with_container_without_arguments(ExporterInterface $export, StatementInterface $body, ContainerInterface $container) { $body->compile($export)->willReturn('return $argument1'); $container->getIterator()->willReturn(new \ArrayIterator([$body->getWrappedObject()])); $this->beConstructedWith([], $container); $this->compile($export)->shouldReturn("function () {\n return \$argument1;\n}"); }
function it_renders_statement_as_return(StatementInterface $statement, ExporterInterface $export) { $statement->compile($export)->willReturn('$this'); $this->beConstructedWith($statement); $this->shouldImplement('EcomDev\\Compiler\\StatementInterface'); $this->compile($export)->shouldReturn('return $this'); }
/** * Returns compiles object access * * @param ExporterInterface $export * * @return string */ public function compile(ExporterInterface $export) { $object = $this->object->compile($export); if ($this->property instanceof StatementInterface) { return sprintf('%s->{%s}', $object, $this->property->compile($export)); } return sprintf('%s->%s', $object, $this->property); }
function it_allows_statement_as_callee(ExporterInterface $export, StatementInterface $statement) { $export->export('argument')->willReturn("'argument'"); $statement->compile($export)->willReturn('$this->methodName'); $export->export(3)->willReturn('3'); $this->beConstructedWith($statement, ['argument']); $this->compile($export)->shouldReturn('$this->methodName(\'argument\')'); }
/** * Compiles a statement * * @param ExporterInterface $export * * @return string */ public function compile(ExporterInterface $export) { $array = $this->array->compile($export); $key = $this->key; if ($key === null) { return sprintf('%s[]', $array); } return sprintf('%s[%s]', $array, $export->export($key)); }
/** * Compiles a call statement * * @param ExporterInterface $export * * @return string */ public function compile(ExporterInterface $export) { $callee = $this->callee; if ($callee instanceof StatementInterface) { $callee = $this->callee->compile($export); } $arguments = []; foreach ($this->arguments as $argument) { $arguments[] = $export->export($argument); } return sprintf('%s(%s)', $callee, implode(', ', $arguments)); }
function it_allows_setting_array_item_value_in_chain(StatementInterface $statement) { $export = new Exporter(); $statement->compile($export)->willReturn('$foo'); $this->foo[1]->bar(1, 2)->foo[1] = 'test'; $this->end()->compile($export)->shouldReturn('$foo->foo[1]->bar(1, 2)->foo[1] = \'test\''); }
/** * Compiles an assignment statement * * @param ExporterInterface $export * * @return string */ public function compile(ExporterInterface $export) { $template = '%s %s %s'; if (($this->left instanceof Operator || $this->right instanceof Operator) && isset($this->precedenceTemplate[$this->operator])) { $template = sprintf('%s %%s %s', $this->left instanceof Operator ? $this->precedenceTemplate[$this->operator] : '%s', $this->right instanceof Operator ? $this->precedenceTemplate[$this->operator] : '%s'); } return sprintf($template, $this->left->compile($export), $this->operator, $this->right->compile($export)); }
function it_should_export_statement_via_its_compile_method(StatementInterface $statement) { $statement->compile($this)->willReturn('new PHP\\Class()'); $this->export($statement)->shouldEqual('new PHP\\Class()'); }
function it_creates_new_closure_return_statement(StatementInterface $body) { $export = new Exporter(); $body->compile($export)->willReturn('return true')->shouldBeCalled(); $return = $this->returnClosure(['arg1', 'arg2'], [$body]); $return->compile($export)->shouldReturn(sprintf('return function ($arg1, $arg2) {%1$s %2$s%1$s}', PHP_EOL, 'return true;')); }