Esempio n. 1
0
    public function testPropertyCreation()
    {
        $gClass = new GClass('TestClass');
        // private $name;
        $name = $gClass->createProperty('name', GProperty::MODIFIER_PRIVATE);
        $this->assertInstanceOf('Psc\\Code\\Generate\\GProperty', $name);
        $this->assertTrue($name->isPrivate());
        $this->assertEquals('name', $name->getName());
        // hihi
        // protected $label = NULL;
        $label = $gClass->createProperty('label', GProperty::MODIFIER_PROTECTED, NULL);
        $this->assertInstanceOf('Psc\\Code\\Generate\\GProperty', $label);
        $this->assertTrue($label->isProtected());
        $this->assertEquals('label', $label->getName());
        $this->assertEquals(NULL, $label->getDefaultValue());
        $this->assertTrue($label->hasDefaultValue());
        $gClass->removeDefaultValue($label);
        $this->assertFalse($label->hasDefaultValue());
        // protected $label = 'datgleischewiename';
        $this->assertInstanceOf('Psc\\Code\\Generate\\GProperty', $label->setDefaultValue('datgleischewiename'));
        $this->assertEquals('datgleischewiename', $label->getDefaultValue());
        $this->assertTrue($gClass->hasDefaultValue($label));
        // public $unsafe;
        $unsafe = $gClass->createProperty('unsafe', GProperty::MODIFIER_PUBLIC);
        $this->assertInstanceOf('Psc\\Code\\Generate\\GProperty', $unsafe);
        $this->assertTrue($unsafe->isPublic());
        $this->assertFalse($unsafe->hasDefaultValue());
        $this->assertFalse($gClass->hasDefaultValue($unsafe));
        $classCode = <<<'CLASS_END'
class TestClass {
  
  private $name;
  
  protected $label = 'datgleischewiename';
  
  public $unsafe;
}
CLASS_END;
        $this->assertEquals($classCode, $gClass->php());
    }
Esempio n. 2
0
 public function createStub(GClass $class)
 {
     $setupCode = "\$this->chainClass = '%s';\n";
     $setupCode .= "parent::setUp();\n";
     if ($this->class->isAbstract()) {
         $setupCode .= '//$this->%s = $this->getMockForAbstractClass($this->chainClass);' . "\n";
     } else {
         $setupCode .= "//\$this->%s = new %s();\n";
     }
     $docBlock = $class->createDocBlock();
     $docBlock->addSimpleAnnotation('group class:' . $this->class->getFQN());
     $class->addMethod(new GMethod('setUp', array(), sprintf($setupCode, $this->class->getFQN(), lcfirst($this->class->getClassName()), $this->class->getClassName())));
     $class->addMethod(new GMethod('testAcceptance', array(), '$this->markTestIncomplete(\'Stub vom Test-Creater\');'));
     //$class->addMethod(new GMethod('create'.$this->class->getClassName(), array(),
     //sprintf("return new %s();",$this->class->getClassName())), GMethod::MODIFIER_PROTECTED);
     $class->createProperty(lcfirst($this->class->getClassName()), GProperty::MODIFIER_PROTECTED);
     return $class;
 }
Esempio n. 3
0
    public function testWithGClass()
    {
        $gClass = new GClass('\\ePaper42\\Entities\\Journal');
        $gClass->setParentClass(new GClass('\\Psc\\XML\\Object'));
        $gClass->createProperty('title')->createDocBlock("Titel des Objektes (Name der Zeitschrift)\n")->addSimpleAnnotation('xml:XmlElement');
        $gClass->createProperty('key')->createDocBlock("Key des Objektes\n")->addSimpleAnnotation('xml:XmlElement');
        $gClass->createProperty('volumes')->createDocBlock("Volumes des Journals (Jahreszahlen)\n")->addSimpleAnnotation('xml:XmlElement', array('name' => 'volumne', 'wrapper' => 'volumeList', 'type' => 'ePaper42\\Entities\\Volume'));
        $classCode = <<<'CLASS_END'
class Journal extends \Psc\XML\Object {
  
  /**
   * Titel des Objektes (Name der Zeitschrift)
   * 
   * @xml:XmlElement
   */
  protected $title;
  
  /**
   * Key des Objektes
   * 
   * @xml:XmlElement
   */
  protected $key;
  
  /**
   * Volumes des Journals (Jahreszahlen)
   * 
   * @xml:XmlElement(name="volumne", wrapper="volumeList", type="ePaper42\Entities\Volume")
   */
  protected $volumes;
}
CLASS_END;
        //file_put_contents('D:\fixture.txt',$classCode);
        //file_put_contents('D:\actual.txt',$gClass->php());
        $this->assertEquals($classCode, $gClass->php());
    }