Esempio n. 1
0
 private static function generateActionTest($config, $pathAction)
 {
     $module = ucfirst($config->module);
     if (self::isReserved($module, $config)) {
         $module .= '_';
     }
     $controller = ucfirst($config->controller);
     if (self::isReserved($controller, $config)) {
         $controller .= '_';
     }
     $action = ucfirst($config->action);
     $className = $module . '\\' . $controller . '\\' . $action . 'Test';
     $class = new UserClass($className);
     $class->extendClass('AbstractModuleTest');
     $class->useClass('integration\\modules\\AbstractModuleTest');
     $class->useClass('TestLib\\Mink');
     $class->addStaticVar('canBeOverWritten', true);
     $doc1 = new CommentBlock();
     $doc1->appendLine('Sets up the fixture, for example, opens a network connection.');
     $doc1->appendLine('This method is called before a test is executed.');
     //$setup = $class->addMethod('protected', 'setUp');
     $setup = new ClassMethod('setUp');
     $setup->setScope('protected');
     //$setup->setCommentBlock($doc1);
     $block = $setup->getBlock();
     $block->appendRenderable(new AssignStatement(new ObjectProperty('$this', 'module'), $config->module));
     $block->appendRenderable(new AssignStatement(new ObjectProperty('$this', 'controller'), $config->controller));
     $block->appendRenderable(new AssignStatement(new ObjectProperty('$this', 'action'), $config->action));
     $block->appendRenderable(new Statement(new StaticMethodCall('parent', 'setUp')));
     $class->addMethodObject($setup);
     $doc2 = new CommentBlock();
     $doc2->appendLine('Tears down the fixture, for example, closes a network connection.');
     $doc2->appendLine('This method is called after a test is executed.');
     $teardown = new ClassMethod('tearDown');
     $teardown->setScope('protected');
     //$teardown->setCommentBlock($doc2);
     $block = $teardown->getBlock();
     $block->appendLine(new Statement(new StaticMethodCall('parent', 'tearDown')));
     $class->addMethodObject($teardown);
     //////////
     $doc3 = new CommentBlock();
     $doc3->appendLine('@covers ' . $config->module . '/' . $config->controller . '/' . $config->action);
     $mainTest = new ClassMethod('test' . $action);
     $mainTest->setScope('public');
     //$mainTest->setCommentBlock($doc3);
     $class->addMethodObject($mainTest);
     $block = $mainTest->getBlock();
     if ($config->inMenu === true && !self::isDanger($config)) {
         $res = self::openInMenuBlock($block, $class, $config);
         if (!$res) {
             fwrite(STDOUT, "\t" . 'cant open: ' . $config->module . ':' . $config->controller . ':' . $config->action . "\n");
             return;
         }
     } else {
         //return;
         self::simpleBlock($block);
     }
     $res = file_put_contents($pathAction, $code = "<?php\n" . $class->render());
     if (!$res) {
         throw new ErrorException('cant write');
     }
 }