/** * Instantiate and configure the node according to this definition * * @return Faker\Components\Engine\Common\Composite\TypeNode The node instance * * @throws InvalidDefinitionException When the definition is invalid */ public function getNode() { $type = new Template($this->templateLoader); $type->setGenerator($this->generator); $type->setUtilities($this->utilities); $type->setLocale($this->locale); foreach ($this->attributes as $attribute => $value) { $type->setOption($attribute, $value); } return new TypeNode('Template', $this->eventDispatcher, $type); }
public function testWithTemplateString() { $utilities = $this->getMockBuilder('Faker\\Components\\Engine\\Common\\Utilities')->disableOriginalConstructor()->getMock(); $generator = $this->getMock('\\PHPStats\\Generator\\GeneratorInterface'); $locale = $this->getMock('\\Faker\\Locale\\LocaleInterface'); $loader = $this->getProject()->getTemplatingManager()->getLoader(); $template = new Template($loader); $template->setGenerator($generator); $template->setLocale($locale); $template->setUtilities($utilities); $template->setOption('template', 'a template string {{ 1 + 1 }}'); $this->assertTrue($template->validate()); $this->assertEquals('a template string 2', $template->generate(1)); }