public function testGenerate()
 {
     $testLocation = 'tmp/gen';
     Skeleton::setTestLocation($testLocation);
     $mockClass = '\\mock\\Phantom';
     $file = 'tests/mock/Phantom.php';
     require_once $file;
     Skeleton\Reverse::setProviderClass($mockClass);
     $file = 'tmp/gen/Administrator/Callrecords/ListTest.php';
     if (file_exists($file)) {
         unlink($file);
     }
     static::assertFileNotExists($file);
     Skeleton::generate();
     static::assertFileExists($file);
     static::assertFileEquals('tests/fixtures/code/listTest.fixture', $file);
 }
Exemple #2
0
 /**
  * @param Block $block
  * @param ClassFile $class
  * @param $config
  * @return bool
  */
 private static function openInMenuBlock(Block $block, UserClass $class, $config)
 {
     fwrite(STDOUT, 'processing: ' . $config->module . ':' . $config->controller . ':' . $config->action . "\n");
     $elements = Reverse::getElements($config);
     if ($elements === false) {
         return false;
     }
     $tryStmt = new TryCatchStatement();
     $block->appendRenderable($tryStmt);
     $tryBlock = $tryStmt->tryBlock;
     $tryBlock->appendRenderable(new Statement(new AssignExpr('$session', new MethodCall('$this', 'getLoggedSession'))));
     $tryBlock->appendRenderable(new Statement(new MethodCall('$this', 'openInMenu', [new ObjectProperty('$this', 'mapModule'), '$session'])));
     $tryBlock->appendRenderable(new Statement(new MethodCall('$this', 'checkWait', ['$session'])));
     $tryBlock->appendRenderable(new Statement(new AssignExpr('$page', new MethodCall('$session', 'getPage'))));
     /** @var FormElement $input */
     foreach ($elements->getInputs() as $input) {
         $tryBlock->appendLine('');
         $tryBlock->appendRenderable(new Comment('input type: ' . $input->getType() . ' label: ' . $input->getLabel()));
         $tryBlock->appendRenderable(new AssignStatement(new Raw($input->getPhpName() . 'Input'), new MethodCall('$page', $input->getFindMethod(), $input->getFindArgs())));
     }
     /** @var Button $button */
     foreach ($elements->getButtons() as $button) {
         $tryBlock->appendLine('');
         //$tryBlock->appendRenderable(
         //    new CommentBlock(explode("\n", var_export($button, true)))
         //);
         $tryBlock->appendRenderable(new Comment('button label: ' . $button->getLabel()));
         $tryBlock->appendRenderable(new AssignStatement(new Raw($button->getPhpName() . 'Button'), new MethodCall('$page', $button->getFindMethod(), $button->getFindArgs())));
     }
     $tryBlock->appendLine('');
     $tryBlock->appendLine('');
     $tryBlock->appendRenderable(new Comment('Implement test here.'));
     $tryBlock->appendLine('');
     $tryBlock->appendLine('');
     $tryBlock->appendRenderable(new Statement(new MethodCall('$this', 'checkErrors', ['$session'])));
     $tryBlock->appendLine('');
     $tryBlock->appendLine('');
     $tryBlock->appendRenderable(new Comment('Remove the following lines when you implement this test.'));
     /*        $tryBlock->appendRenderable(
               new Statement(new StaticMethodCall('static', 'markTestIncomplete', ['This test has not been implemented yet . '])));*/
     $tryBlock->appendLine('');
     $tryBlock->appendLine('');
     $throwBlock = $tryStmt->catchBlock;
     $throwBlock->appendRenderable(new Statement(new MethodCall(new StaticMethodCall('Mink', 'getInstance'), 'ss')));
     $throwBlock->appendRenderable(new Comment('Remove the following lines when you implement this test.'));
     /*        $throwBlock->appendRenderable(
               new Statement(new StaticMethodCall('static', 'markTestIncomplete', ['This test has not been implemented yet . '])));*/
     if ($elements->getDataTables()) {
         foreach ($elements->getDataTables() as $key => $dataTable) {
             $doc = new CommentBlock();
             $doc->appendLine('Datatable tests');
             $dtTest = new ClassMethod('testDataTable' . ($key + 1));
             $dtTest->setScope('public');
             //$dtTest->setCommentBlock($doc);
             $block = $dtTest->getBlock();
             self::createDataTableTest($dataTable, $block);
             $class->addMethodObject($dtTest);
         }
     }
     return true;
 }