Author: Thomas Gossmann
 public function testReturnType()
 {
     $expected = "public function foo(): int {\n}\n";
     $generator = new ModelGenerator(['generateReturnTypeHints' => true, 'generateDocblock' => false]);
     $method = PhpMethod::create('foo')->setType('int');
     $this->assertEquals($expected, $generator->generate($method));
 }
 public function testSignature()
 {
     $expected = 'trait MyTrait {' . "\n" . '}';
     $trait = PhpTrait::create('MyTrait');
     $generator = new ModelGenerator();
     $code = $generator->generate($trait);
     $this->assertEquals($expected, $code);
 }
 public function testExtends()
 {
     $generator = new ModelGenerator();
     $expected = 'interface MyInterface extends \\Iterator {' . "\n" . '}';
     $interface = PhpInterface::create('MyInterface')->addInterface('\\Iterator');
     $this->assertEquals($expected, $generator->generate($interface));
     $expected = 'interface MyInterface extends \\Iterator, \\ArrayAccess {' . "\n" . '}';
     $interface = PhpInterface::create('MyInterface')->addInterface('\\Iterator')->addInterface('\\ArrayAccess');
     $this->assertEquals($expected, $generator->generate($interface));
 }
 public function testValues()
 {
     $generator = new ModelGenerator();
     $prop = PhpParameter::create('foo')->setValue('string');
     $this->assertEquals('$foo = \'string\'', $generator->generate($prop));
     $prop = PhpParameter::create('foo')->setValue(300);
     $this->assertEquals('$foo = 300', $generator->generate($prop));
     $prop = PhpParameter::create('foo')->setValue(162.5);
     $this->assertEquals('$foo = 162.5', $generator->generate($prop));
     $prop = PhpParameter::create('foo')->setValue(true);
     $this->assertEquals('$foo = true', $generator->generate($prop));
     $prop = PhpParameter::create('foo')->setValue(false);
     $this->assertEquals('$foo = false', $generator->generate($prop));
     $prop = PhpParameter::create('foo')->setValue(null);
     $this->assertEquals('$foo = null', $generator->generate($prop));
     $prop = PhpParameter::create('foo')->setValue(PhpConstant::create('BAR'));
     $this->assertEquals('$foo = BAR', $generator->generate($prop));
     $prop = PhpParameter::create('foo')->setExpression("['bar' => 'baz']");
     $this->assertEquals('$foo = [\'bar\' => \'baz\']', $generator->generate($prop));
 }
 public function testValues()
 {
     $generator = new ModelGenerator();
     $prop = PhpProperty::create('foo')->setValue('string');
     $this->assertEquals('public $foo = \'string\';' . "\n", $generator->generate($prop));
     $prop = PhpProperty::create('foo')->setValue(300);
     $this->assertEquals('public $foo = 300;' . "\n", $generator->generate($prop));
     $prop = PhpProperty::create('foo')->setValue(162.5);
     $this->assertEquals('public $foo = 162.5;' . "\n", $generator->generate($prop));
     $prop = PhpProperty::create('foo')->setValue(true);
     $this->assertEquals('public $foo = true;' . "\n", $generator->generate($prop));
     $prop = PhpProperty::create('foo')->setValue(false);
     $this->assertEquals('public $foo = false;' . "\n", $generator->generate($prop));
     $prop = PhpProperty::create('foo')->setValue(null);
     $this->assertEquals('public $foo = null;' . "\n", $generator->generate($prop));
     $prop = PhpProperty::create('foo')->setValue(PhpConstant::create('BAR'));
     $this->assertEquals('public $foo = BAR;' . "\n", $generator->generate($prop));
     $prop = PhpProperty::create('foo')->setExpression("['bar' => 'baz']");
     $this->assertEquals('public $foo = [\'bar\' => \'baz\'];' . "\n", $generator->generate($prop));
 }
Exemplo n.º 6
0
 /**
  * @param AbstractModel $model
  * @return void
  */
 protected function generate(AbstractModel $model)
 {
     $builder = $this->generator->getFactory()->getBuilder($model);
     $builder->build($model);
 }
 public function testRequireTraitsClass()
 {
     $class = PhpClass::create('RequireTraitsClass')->addRequiredFile('FooBar.php')->addRequiredFile('ABClass.php')->addTrait('Iterator');
     $generator = new ModelGenerator();
     $code = $generator->generate($class);
     $this->assertEquals($this->getGeneratedContent('RequireTraitsClass.php'), $code);
 }
Exemplo n.º 8
0
 /**
  * Generates code from a given model
  *
  * @param GenerateableInterface $model
  * @return string the generated code
  */
 public function generate(GenerateableInterface $model)
 {
     return $this->generator->generate($model);
 }