Beispiel #1
0
 /**
  * Create a PhpMethod code generation object named after a given alias
  * 
  * @param  string $alias 
  * @param  class $class Class to which alias refers
  * @return CodeGen\PhpMethod
  */
 protected function getCodeGenMethodFromAlias($alias, $class)
 {
     $alias = $this->normalizeAlias($alias);
     $method = new CodeGen\PhpMethod();
     $method->setName($alias)->setBody(sprintf('return $this->get(\'%s\');', $class));
     return $method;
 }
Beispiel #2
0
    /**
     * @group ZF-7268
     */
    public function testDefaultValueGenerationDoesNotIncludeTrailingSemicolon()
    {
        $method = new Php\PhpMethod(array(
            'name' => 'setOptions',
        ));
        $default = new Php\PhpParameterDefaultValue();
        $default->setValue(array());

        $param   = new Php\PhpParameter(array(
            'name' => 'options',
            'type' => 'array',
        ));
        $param->setDefaultValue($default);

        $method->setParameter($param);
        $generated = $method->generate();
        $this->assertRegexp('/array \$options = array\(\)\)/', $generated, $generated);
    }
Beispiel #3
0
 /**
  * @group ZF-7361
  */
 public function testHasMethod()
 {
     $method = new Php\PhpMethod();
     $method->setName('methodOne');
     $codeGenClass = new Php\PhpClass();
     $codeGenClass->setMethod($method);
     $this->assertTrue($codeGenClass->hasMethod('methodOne'));
 }
Beispiel #4
0
    /**
     * @group ZF-7205
     */
    public function testMethodCanHaveDocblock()
    {
        $codeGenProperty = new Php\PhpMethod(array('name' => 'someFoo', 'static' => true, 'visibility' => 'protected', 'docblock' => '@var string $someVal This is some val'));
        $expected = <<<EOS
    /**
     * @var string \$someVal This is some val
     */
    protected static function someFoo()
    {
    }

EOS;
        $this->assertEquals($expected, $codeGenProperty->generate());
    }