public function testCreate()
 {
     $class = PhpClass::create();
     $this->assertTrue($class instanceof PhpClass);
     $interface = PhpInterface::create();
     $this->assertTrue($interface instanceof PhpInterface);
     $trait = PhpTrait::create();
     $this->assertTrue($trait instanceof PhpTrait);
 }
Пример #2
0
 /**
  * Creates ClassWithComments
  * 
  * @return PhpClass
  */
 public static function createClassWithComments()
 {
     $class = PhpClass::create('gossi\\codegen\\tests\\fixtures\\ClassWithComments');
     $class->setDescription('A class with comments');
     $class->setLongDescription('Here is a super dooper long-description');
     $docblock = $class->getDocblock();
     $docblock->appendTag(AuthorTag::create('gossi'));
     $docblock->appendTag(SinceTag::create('0.2'));
     $class->setConstant(PhpConstant::create('FOO', 'bar')->setDescription('Best const ever')->setLongDescription('Aaaand we go along long')->setType('string')->setTypeDescription('baz'));
     $class->setProperty(PhpProperty::create('propper')->setDescription('best prop ever')->setLongDescription('Aaaand we go along long long')->setType('string')->setTypeDescription('Wer macht sauber?'));
     $class->setMethod(PhpMethod::create('setup')->setDescription('Short desc')->setLongDescription('Looong desc')->addParameter(PhpParameter::create('moo')->setType('boolean')->setTypeDescription('makes a cow'))->addParameter(PhpParameter::create('foo')->setType('foo', 'makes a fow'))->setType('boolean', 'true on success and false if it fails'));
     return $class;
 }
 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);
 }
 public function testMethodReturnTypeHinting()
 {
     $class = PhpClass::create()->setName('GenerationTestClass')->setMethod(PhpMethod::create('a')->addParameter(PhpParameter::create('b'))->setType('int'));
     $expected = "class GenerationTestClass {\n\n\tpublic function a(\$b): int {\n\t}\n}";
     $codegen = new CodeGenerator(['generateDocblock' => false, 'generateEmptyDocblock' => false, 'generateReturnTypeHints' => true]);
     $code = $codegen->generate($class);
     $this->assertEquals($expected, $code);
 }
 /**
  *
  * @return PhpClass
  */
 private function getClass()
 {
     $class = PhpClass::create()->setName('GenerationTestClass')->setMethod(PhpMethod::create('a'))->setMethod(PhpMethod::create('b'))->setProperty(PhpProperty::create('a'))->setProperty(PhpProperty::create('b'))->setConstant('a', 'foo')->setConstant('b', 'bar');
     return $class;
 }