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; }
/** * @TODO test interfaces und extends! */ public function testClass() { $cr = "\n"; $class = GClass::factory(__NAMESPACE__ . '\\TestClass'); $this->assertInstanceOf('Psc\\Code\\Generate\\GMethod', $class->getMethod('method2')); $this->assertInstanceOf('Psc\\Code\\Generate\\GProperty', $class->getProperty('prop1')); $gClass = new GClass('Psc\\Code\\Generate\\GClass'); $this->assertEquals('GClass', $gClass->getClassName()); $this->assertEquals('\\Psc\\Code\\Generate', $gClass->getNamespace()); $this->assertEquals('Psc\\Code\\Generate\\GClass', $gClass->getFQN()); /* test final + abstract zeuch */ $this->assertFalse($gClass->isFinal()); $this->assertFalse($gClass->isAbstract()); $gClass->setFinal(TRUE); $this->assertTrue($gClass->isFinal()); $gClass->setAbstract(TRUE); $this->assertTrue($gClass->isAbstract()); $gClass->setModifier(GClass::MODIFIER_ABSTRACT, FALSE); $gClass->setModifier(GClass::MODIFIER_FINAL, FALSE); $this->assertFalse($gClass->isAbstract()); $this->assertFalse($gClass->isFinal()); /* testClass (denn da wissen wir die line-nummern besser und die ist auch abstract */ $testClass = new GClass(new ReflectionClass(__NAMESPACE__ . '\\TestClass')); $this->assertTrue($testClass->isAbstract()); $this->assertFalse($testClass->isFinal()); $this->assertEquals(self::$startLine, $testClass->getStartLine()); $this->assertEquals(self::$endLine, $testClass->getEndLine()); $testHint = new GClass('SomeClassForAHint'); $this->assertEquals('class SomeClassForAHint {' . $cr . '}', $testHint->php(), sprintf("output: '%s'", $testHint->php())); //file_put_contents('D:\fixture.txt', self::$testClassCode); //file_put_contents('D:\compiled.txt',$testClass->php()); $this->assertEquals(self::$testClassCode, $testClass->php(), 'Code für Klasse ist nicht identisch'); //identisch bis auf whitespaces! (das ist irgendwie ein bissl variabel, aber okay // geiler wäre halt assertEqualsCode, hmmm das ginge sogar mit token_get_all und so? }
public function testIsAbstract() { // class is not elevated, so that is wrong! $gClass = new GClass(__NAMESPACE__ . '\\MyAbstractClass'); $this->assertFalse($gClass->isAbstract()); // its right this way $gClass = GClass::factory(__NAMESPACE__ . '\\MyAbstractClass'); $this->assertTrue($gClass->isAbstract()); }