function it_takes_argument_as_initial_list(ExporterInterface $export) { $this->beConstructedWith(['item1', 'item2']); $this->add('item3')->shouldReturn($this); $export->export('item1')->willReturn("'item1'"); $export->export('item2')->willReturn("'item2'"); $export->export('item3')->willReturn("'item3'"); $this->compile($export)->shouldReturn("[\n 'item1',\n 'item2',\n 'item3'\n]"); }
/** * Return exported PHP code * * @param ExportableInterface|StatementInterface|mixed $value * * @return string */ private function export($value) { if ($value instanceof ExportableInterface) { $value = $this->objectBuilder->build($value); } return $this->exporter->export($value); }
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\')'); }
/** * Exports array list * * @param ExporterInterface $export * * @return string */ public function compile(ExporterInterface $export) { $itemPrefix = ''; $itemWhitespace = ' '; $pattern = '[%s]'; if (count($this->list) > 2) { $itemWhitespace = "\n"; $itemPrefix = str_pad('', 4, ' '); $pattern = "[\n%s\n]"; } $exportedList = []; foreach ($this->list as $item) { $exportedList[] = sprintf('%s%s', $itemPrefix, $export->export($item)); } return sprintf($pattern, implode(sprintf(',%s', $itemWhitespace), $exportedList)); }
/** * Compiles normal scalar value * * @param ExporterInterface $export * * @return string */ public function compile(ExporterInterface $export) { return $export->export($this->value); }
/** * @param ExporterInterface $export * @param array $values */ private function stubExport($export, array $values) { foreach ($values as $value) { $export->export($value)->willReturn(var_export($value, true)); } }
function it_uses_export_model_to_export_a_value(ExporterInterface $export) { $export->export('dummy')->willReturn("'dummy'"); $this->compile($export)->shouldBe("'dummy'"); }
function it_renders_scalar_as_return(ExporterInterface $export) { $export->export('$this')->willReturn("'\$this'"); $this->beConstructedWith('$this'); $this->compile($export)->shouldReturn("return '\$this'"); }