public function create($overwrite = false) { try { $this->class->elevateClass(); // @todo das mal konfigurieren und fixen } catch (\Exception $e) { $this->log('Klasse für den Test kann nicht elevated werden: ' . $e->getMessage()); } catch (\Psc\Code\Generate\ReflectionException $e) { $this->log('Klasse für den Test kann nicht elevated werden: ' . $e->getMessage()); } $class = new GClass(); $class->setName($this->class->getClassName() . 'Test'); $class->setNamespace($this->class->getNamespace()); $class->setParentClass($this->testClass); $writer = new ClassWriter(); $writer->setClass($class); $class = $this->createStub($class); $file = $this->getTestFile(); if (isset($this->createCallback)) { $class = call_user_func($this->createCallback, $class, $this, $writer, $file); } $writer->addImport($this->class); // not really necessary (weil ist ja derselbe NS, aber who knows) $file->getDirectory()->create(); $writer->write($file, array(), $overwrite); return $file; }
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()); }