コード例 #1
0
ファイル: GenerationTest.php プロジェクト: pscheit/psc-cms
    public function testNewClass()
    {
        $class = new GClass();
        $class->setName('tiptoi\\Entities\\Page');
        // da dieser Test in keinem NS ist
        $this->assertEquals('\\tiptoi\\Entities', $class->getNamespace());
        $this->assertEquals('Page', $class->getClassName());
        $class->addMethod(GMethod::factory('addOID', array(GParameter::factory('$oid', GClass::factory('OID'))), 'if (!$this->oids->contains($oid)) {
  $this->oids->add($oid);
}

return $this;
'));
        $class->setMethod(GMethod::factory('removeOID', array(GParameter::factory('$oid', GClass::factory('OID'))), 'if ($this->oids->contains($oid)) {
  $this->oids->removeElement($oid);
}

return $this;
'));
        $class->addMethod(GMethod::factory('getOIDs', array(), 'return $this->oids;'));
        $classCode = <<<'CLASS_CODE'
class Page {
  
  public function addOID(OID $oid) {
    if (!$this->oids->contains($oid)) {
      $this->oids->add($oid);
    }
    
    return $this;
  }
  
  public function removeOID(OID $oid) {
    if ($this->oids->contains($oid)) {
      $this->oids->removeElement($oid);
    }
    
    return $this;
  }
  
  public function getOIDs() {
    return $this->oids;
  }
}
CLASS_CODE;
        //    file_put_contents('D:\fixture.txt', $classCode);
        //    file_put_contents('D:\compiled.txt',$class->php());
        $this->assertEquals($classCode, $class->php());
    }
コード例 #2
0
ファイル: GClassTest.php プロジェクト: pscheit/psc-cms
 public function testMethodOrdering()
 {
     $gClass = new GClass(__NAMESPACE__ . '\\OrderedMethods');
     $gClass->setParentClass(new GClass(__NAMESPACE__ . '\\MyDocTestClass'));
     $gClass->createMethod('getIdentifier');
     $gClass->createMethod('getObjectName');
     $gClass->createMethod('setLabel', array(new GParameter('label')));
     $gClass->createMethod('getLabel');
     $gClass->addMethod(new GMethod('__construct'), GClass::PREPEND);
     $classWriter = new ClassWriter($gClass);
     $classWriter->write($out = $this->newFile('class.OrderedMethods.php'), array(), ClassWriter::OVERWRITE);
     require $out;
     $gClass = GClass::factory(__NAMESPACE__ . '\\OrderedMethods');
     $getMethodNames = function (array $methods) {
         $methodNames = array();
         foreach ($methods as $method) {
             $methodNames[] = $method->getName();
         }
         return $methodNames;
     };
     $this->assertEquals(array('__construct', 'getIdentifier', 'getObjectName', 'setLabel', 'getLabel'), $getMethodNames($gClass->getMethods()));
     $this->assertEquals(array('__construct', 'getIdentifier', 'getObjectName', 'setLabel', 'getLabel', 'getName'), $getMethodNames($gClass->getAllMethods()));
     // parent methods behind
     $gClass->setMethodOrder($gClass->getMethod('getLabel'), 1);
     $this->assertEquals(array('__construct', 'getLabel', 'getIdentifier', 'getObjectName', 'setLabel'), $getMethodNames($gClass->getMethods()));
 }
コード例 #3
0
ファイル: TestCreater.php プロジェクト: pscheit/psc-cms
 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;
 }