예제 #1
0
    public function testFromReflection()
    {
        if (PHP_VERSION_ID < 70000) {
            $this->markTestSkipped("Test is only valid for PHP >=7");
        }
        $class = new PhpClass();
        $class->setName('CG\\Tests\\Generator\\Fixture\\EntityPhp7')->setDocblock('/**
 * Doc Comment.
 *
 * @author Johannes M. Schmitt <*****@*****.**>
 */')->setProperty(PhpProperty::create('id')->setVisibility('private')->setDefaultValue(0)->setDocblock('/**
 * @var integer
 */'));
        $class->setMethod(PhpMethod::create()->setName('getId')->setDocblock('/**
 * @return int
 */')->setVisibility('public')->setReturnType('int'));
        $class->setMethod(PhpMethod::create()->setName('setId')->setVisibility('public')->setDocBlock('/**
 * @param int $id
 * @return EntityPhp7
 */')->addParameter(PhpParameter::create()->setName('id')->setType('int')->setDefaultValue(null))->setReturnType('self'));
        $class->setMethod(PhpMethod::create()->setName('getTime')->setVisibility('public')->setReturnType('DateTime'));
        $class->setMethod(PhpMethod::create()->setName('getTimeZone')->setVisibility('public')->setReturnType('DateTimeZone'));
        $class->setMethod(PhpMethod::create()->setName('setTime')->setVisibility('public')->addParameter(PhpParameter::create()->setName('time')->setType('DateTime')));
        $class->setMethod(PhpMethod::create()->setName('setTimeZone')->setVisibility('public')->addParameter(PhpParameter::create()->setName('timezone')->setType('DateTimeZone')));
        $class->setMethod(PhpMethod::create()->setName('setArray')->setVisibility('public')->setReturnType('array')->addParameter(PhpParameter::create()->setName('array')->setDefaultValue(null)->setPassedByReference(true)->setType('array')));
        $class->setMethod(PhpMethod::create()->setName('getFoo')->setReturnType('CG\\Tests\\Generator\\Fixture\\SubFixture\\Foo'));
        $class->setMethod(PhpMethod::create()->setName('getBar')->setReturnType('CG\\Tests\\Generator\\Fixture\\SubFixture\\Bar'));
        $class->setMethod(PhpMethod::create()->setName('getBaz')->setReturnType('CG\\Tests\\Generator\\Fixture\\SubFixture\\Baz'));
        $this->assertEquals($class, PhpClass::fromReflection(new \ReflectionClass('CG\\Tests\\Generator\\Fixture\\EntityPhp7')));
    }
예제 #2
0
    public function testFromReflection()
    {
        $class = new PhpClass();
        $class->setName('CG\\Tests\\Generator\\Fixture\\Entity')->setAbstract(true)->setDocblock('/**
 * Doc Comment.
 *
 * @author Johannes M. Schmitt <*****@*****.**>
 */')->setProperty(PhpProperty::create('id')->setVisibility('private')->setDocblock('/**
 * @var integer
 */'))->setProperty(PhpProperty::create('enabled')->setVisibility('private')->setDefaultValue(false));
        $method = PhpMethod::create()->setName('__construct')->setFinal(true)->addParameter(new PhpParameter('a'))->addParameter(PhpParameter::create()->setName('b')->setType('array')->setPassedByReference(true))->addParameter(PhpParameter::create()->setName('c')->setType('stdClass'))->addParameter(PhpParameter::create()->setName('d')->setDefaultValue('foo'))->setDocblock('/**
 * Another doc comment.
 *
 * @param unknown_type $a
 * @param array        $b
 * @param \\stdClass    $c
 * @param string       $d
 */');
        $class->setMethod($method);
        $class->setMethod(PhpMethod::create()->setName('foo')->setAbstract(true)->setVisibility('protected'));
        $class->setMethod(PhpMethod::create()->setName('bar')->setStatic(true)->setVisibility('private'));
        $this->assertEquals($class, PhpClass::fromReflection(new \ReflectionClass('CG\\Tests\\Generator\\Fixture\\Entity')));
    }