Esempio n. 1
0
 public function loadFixtureGClass($className)
 {
     $file = $this->getFile('fixture.' . $className . '.php');
     require_once $file;
     $gClass = GClass::factory('Psc\\Code\\Compile\\Tests\\' . $className);
     return $gClass;
 }
 protected function getCClass(File $out, $className = 'NormalClass')
 {
     // das hier ist nicht wahr
     //$this->assertFalse(class_exists('Psc\System\Console\NormalClass',FALSE));
     // weil der commandTester die Klasse lädt (bzw der Command) müssen wir die $out file hier umbenennen um das Ergebnis testen zu können
     $ccName = 'Compiled' . $className;
     $out->writeContents(str_replace('class ' . $className . ' ', 'class ' . $ccName . ' ', $out->getContents()));
     require $out;
     $gClass = GClass::factory('Psc\\System\\Console\\' . $ccName);
     return $gClass;
 }
Esempio n. 3
0
 public function testStub()
 {
     $gClass = new GClass('Psc\\Code\\Generate\\MyTestClass');
     $out = $this->newFile('MyTestClassTest.php');
     $out->delete();
     $tc = $this->getMock('Psc\\Code\\Generate\\TestCreater', array('getTestFile'), array($gClass));
     $tc->expects($this->once())->method('getTestFile')->will($this->returnValue($out));
     $outTc = $tc->create();
     $this->assertSame($out, $outTc);
     // checkt ob unser mock geklappt hat
     require $out;
     $this->assertTrue(class_exists('Psc\\Code\\Generate\\MyTestClassTest', FALSE));
     $test = GClass::factory('Psc\\Code\\Generate\\MyTestClassTest');
     $db = $test->getDocBlock();
     $this->assertContains('@group class:Psc\\Code\\Generate\\MyTestClass', $db->toString());
     $this->assertTrue($test->hasMethod('setUp'), 'methode setUp existiert nicht im Test');
     $this->assertTrue($test->hasMethod('testAcceptance'), 'methode testAcceptance existiert nicht im Test');
     $this->assertEquals('Psc\\Code\\Test\\Base', $test->getParentClass()->getFQN());
     // achtung das hier ist kein instanceof
 }
Esempio n. 4
0
 public function testConstructInterfaceHierarchy()
 {
     return $this->assertTrue(true, 'einkommentieren zum compilieren');
     $avaibleInterfaces = array('ComboDropBoxable', 'DropBoxButtonable', 'SelectComboBoxable', 'GridRowable', 'RightContentLinkable', 'Searchable', 'AutoCompletable', 'Patchable', 'NewButtonable', 'NewTabButtonable', 'DeleteButtonable', 'EditButtonable', 'TabButtonable', 'TabLinkable', 'TabOpenable', 'Buttonable', 'Deleteable', 'Identifyable');
     $hierarchy = array();
     foreach ($avaibleInterfaces as $avaibleInterface) {
         $hierarchy[$avaibleInterface] = array();
         foreach (GClass::factory('Psc\\CMS\\Item\\' . $avaibleInterface)->getAllInterfaces() as $interface) {
             if ($interface->getNamespace() === '\\Psc\\CMS\\Item') {
                 $hierarchy[$avaibleInterface][] = $interface->getFQN();
             }
         }
     }
     $codeWriter = new \Psc\Code\Generate\CodeWriter();
     $code = '    $avaibleInterfaces = Array(' . "\n";
     foreach ($hierarchy as $trait => $interfaces) {
         $code .= sprintf("      '%s' => %s,\n", $trait, $codeWriter->exportList($interfaces));
     }
     $code .= '    );' . "\n";
     print "\n\n";
     print $code;
     print "\n";
 }
Esempio n. 5
0
 protected function getCompiler()
 {
     $input = $this->execInput;
     $output = $this->execOutput;
     $class = $input->getArgument('class');
     $file = $this->getInFile();
     if ($class === 'inFile') {
         $parser = new \Psc\Doctrine\PhpParser();
         if (($class = $parser->findFirstClass((string) $file)) == NULL) {
             throw new \Psc\Exception('inFile kann keine Klasse ermitteln. Es wurden keine Klassen in der Datei gefunden');
         }
     }
     if (!class_exists($class, FALSE)) {
         require $file;
     }
     if (!class_exists($class, FALSE)) {
         throw new \InvalidArgumentException('Klasse ' . $class . ' konnte nicht in Datei ' . $file . ' gefunden werden');
     }
     $gClass = GClass::factory($class);
     $classReader = new ClassReader($file, $gClass);
     $compiler = new Compiler($classReader);
     return $compiler;
 }
Esempio n. 6
0
use Psc\System\System;
use Psc\Code\Generate\ClassWriter;
use Webforge\Common\JS\JSONConverter;
use Psc\JS\jQuery;
use Seld\JsonLint\JsonParser;
/**
 *
 * $createCommand = function ($name, array|closure $configure, closure $execute) {
 * 
 * $arg = function ($name, $description = NULL, $required = TRUE) // default: required
 * $opt = function($name, $short = NULL, $withValue = TRUE, $description = NULL) // default: mit value required
 * $flag = function($name, $short = NULL, $description) // ohne value
 */
$createCommand('compile:komodo-command-call', array($arg('extension-name')), function ($input, $output, $command) {
    $extensionClass = Code::expandNamespace(\Webforge\Common\String::expand($input->getArgument('extension-name'), 'Extension'), 'Psc\\Code\\Compile');
    $extension = GClass::factory($extensionClass);
    $fields = array();
    if ($extension->hasMethod('__construct')) {
        foreach ($extension->getMethod('__construct')->getParameters() as $param) {
            $fields[] = $param->getName();
        }
    }
    // das nimmt vielleicht zu viele, weis nicht, alternativ würds auch ne statische methode zur extension tun
    foreach ($extension->getProperties() as $property) {
        $fields[] = $property->getName();
    }
    $json = array();
    foreach (array_unique($fields) as $field) {
        $json[$field] = '%(ask:' . $field . ')';
    }
    $command->comment(sprintf('Komodo-Command für %s:', $extension->getClassName()));
Esempio n. 7
0
 /**
  * @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?
 }
Esempio n. 8
0
 protected function parseExtensionGClass($input)
 {
     $extensionClass = Code::expandNamespace(\Webforge\Common\String::expand($input->getArgument('name'), 'Extension'), 'Psc\\Code\\Compile');
     return GClass::factory($extensionClass);
 }
Esempio n. 9
0
 public function testOwnMethodForAbstractClassImplementingAnInterface()
 {
     $gClass = GClass::factory(__NAMESPACE__ . '\\MyAbstractInterfacedClass');
     $this->assertFalse($gClass->hasOwnMethod('interfaceMethod1'));
     $this->assertTrue($gClass->hasMethod('interfaceMethod1'));
 }
Esempio n. 10
0
 public function __construct($annotationClass, array $properties = array())
 {
     $this->annotationClass = GClass::factory($annotationClass);
     $this->annotation = new $annotationClass($properties);
     $this->setProperties($properties);
 }
Esempio n. 11
0
 /**
  * wird automatisch mit dependencies erstellt
  * @param string $name der Name des Tasks ohne Namespace und "Task" dahinter
  */
 public function createTask($name)
 {
     $this->init();
     $class = Code::expandNamespace(\Webforge\Common\String::expand($name, 'Task'), 'Psc\\System\\Deploy');
     $gClass = GClass::factory($class);
     $params = array();
     if ($gClass->hasMethod('__construct')) {
         $constructor = $gClass->getMethod('__construct');
         foreach ($constructor->getParameters() as $parameter) {
             $params[] = $this->resolveTaskDependency($parameter, $gClass);
         }
     }
     return $gClass->newInstance($params);
 }