Example #1
0
 /**
  * @param array $requestArguments
  * @param bool $failOnFailure
  * @return Response
  */
 protected function fetchFrontendResponse(array $requestArguments, $failOnFailure = true)
 {
     if (!empty($requestArguments['url'])) {
         $requestUrl = '/' . ltrim($requestArguments['url'], '/');
     } else {
         $requestUrl = '/?' . GeneralUtility::implodeArrayForUrl('', $requestArguments);
     }
     if (property_exists($this, 'instancePath')) {
         $instancePath = $this->instancePath;
     } else {
         $instancePath = ORIGINAL_ROOT . 'typo3temp/functional-' . substr(sha1(get_class($this)), 0, 7);
     }
     $arguments = array('documentRoot' => $instancePath, 'requestUrl' => 'http://localhost' . $requestUrl);
     $template = new \Text_Template(ORIGINAL_ROOT . 'typo3/sysext/core/Tests/Functional/Fixtures/Frontend/request.tpl');
     $template->setVar(array('arguments' => var_export($arguments, true), 'originalRoot' => ORIGINAL_ROOT));
     $php = \PHPUnit_Util_PHP::factory();
     $response = $php->runJob($template->render());
     $result = json_decode($response['stdout'], true);
     if ($result === null) {
         $this->fail('Frontend Response is empty');
     }
     if ($failOnFailure && $result['status'] === Response::STATUS_Failure) {
         $this->fail('Frontend Response has failure:' . LF . $result['error']);
     }
     $response = new Response($result['status'], $result['content'], $result['error']);
     return $response;
 }
 /**
  * @param Release $release
  * @param bool    $latest
  *
  * @return string
  */
 private function renderRelease(Release $release, $latest = false)
 {
     $item = new \Text_Template(__DIR__ . '/../templates/item.html');
     $manifest = '';
     if (!empty($release->manifest())) {
         $manifest = sprintf(' class="phar" data-title="Manifest" data-content="<ul>%s</ul>" data-placement="bottom" data-html="true"', implode('', array_map(function ($item) {
             return '<li>' . $item . '</li>';
         }, $release->manifest())));
     }
     $item->setVar(['domain' => $this->domain(), 'package' => $release->package(), 'version' => $release->version(), 'date' => $release->date(), 'size' => $release->size(), 'sha256' => $release->sha256(), 'strongOpen' => $latest ? '<strong>' : '', 'strongClose' => $latest ? '</strong>' : '', 'manifest' => $manifest]);
     return $item->render();
 }
 /**
  * @param Tombstone $tombstone
  *
  * @return string
  */
 private function renderInvokers(Tombstone $tombstone)
 {
     $invokers = array();
     foreach ($tombstone->getVampires() as $vampire) {
         $invokers[] = $vampire->getInvoker();
     }
     $invokers = array_unique($invokers);
     $invokersString = '';
     foreach ($invokers as $invoker) {
         $this->invokerTemplate->setVar(array('invoker' => $invoker ?: 'global scope'));
         $invokersString .= $this->invokerTemplate->render();
     }
     return $invokersString;
 }
 /**
  * @param ReleaseCollection $releases
  */
 public function render(ReleaseCollection $releases)
 {
     $feedTemplate = new \Text_Template(__DIR__ . '/../templates/feed.xml');
     $feedItemTemplate = new \Text_Template(__DIR__ . '/../templates/item.xml');
     $rdfList = '';
     $rdfItems = '';
     foreach ($releases->latestReleasesSortedByDate() as $release) {
         $rdfList .= sprintf('    <rdf:li rdf:resource="%s/%s-%s.phar"/>' . "\n", $this->domain(), $release->package(), $release->version());
         $feedItemTemplate->setVar(['domain' => $this->domain(), 'package' => $release->package(), 'version' => $release->version(), 'date' => $release->date(), 'content' => '']);
         $rdfItems .= $feedItemTemplate->render();
     }
     $feedTemplate->setVar(['items_list' => $rdfList, 'items' => $rdfItems, 'domain' => $this->domain(), 'email' => $this->email()]);
     $feedTemplate->renderTo($this->target());
 }
 /**
  * @param PrintResultEvent $printResultEvent
  * @throws \Codeception\Exception\ModuleRequireException
  */
 public function resultPrintAfter(PrintResultEvent $printResultEvent)
 {
     if (count($this->failedIdentifiers) > 0) {
         $items = '';
         $itemTemplate = new \Text_Template($this->config['templateFolder'] . 'Item.html');
         foreach ($this->failedIdentifiers as $vars) {
             $itemTemplate->setVar($vars);
             $items .= $itemTemplate->render();
         }
         $pageTemplate = new \Text_Template($this->config['templateFolder'] . 'Page.html');
         $pageTemplate->setVar(array('items' => $items));
         $reportPath = $this->fileSystemUtil->getFailImageDirectory() . 'index.html';
         $pageTemplate->renderTo($reportPath);
         $printResultEvent->getPrinter()->write('Report has been created: ' . $reportPath . "\n");
     }
 }
Example #6
0
$extension = new ReflectionExtension($extname);
$classes = array_keys($extension->getClasses());
$functions = array_keys($extension->getFunctions());
$constants = array_keys($extension->getConstants());
$classItems = array();
foreach ($classes as $classname) {
    $classItems[] = "            " . sprintf("%-40s", "'{$classname}'") . "=> array('{$defversion}', ''),";
}
$functionItems = array();
foreach ($functions as $fctname) {
    $functionItems[] = "            " . sprintf("%-40s", "'{$fctname}'") . "=> array('{$defversion}', ''),";
}
$constantItems = array();
foreach ($constants as $cstname) {
    $constantItems[] = "            " . sprintf("%-40s", "'{$cstname}'") . "=> array('{$defversion}', ''),";
}
$tplDir = dirname(__FILE__) . DIRECTORY_SEPARATOR;
try {
    $skeleton = $tplDir . 'reference.skeleton.tpl';
    $tpl = new Text_Template($skeleton);
    /**
     * Cannot use directly setFile() method, due to issue
     * @link: https://github.com/sebastianbergmann/php-text-template/issues/7
     */
    //$tpl->setFile($skeleton);
    $vars = array('extname' => $extname, 'extversion' => $extversion, 'defversion' => $defversion, 'release' => '2.x.y', 'classes' => implode(PHP_EOL, $classItems), 'functions' => implode(PHP_EOL, $functionItems), 'constants' => implode(PHP_EOL, $constantItems));
    $tpl->setVar($vars);
    echo $tpl->render();
} catch (Exception $e) {
    die($e->getMessage());
}
Example #7
0
 /**
  * @param  string $templateDir
  * @param  string $className
  * @param  string $methodName
  * @param  bool   $cloneArguments
  * @param  string $modifier
  * @param  string $arguments_decl
  * @param  string $arguments_call
  * @param  string $reference
  * @param  bool   $callOriginalMethods
  * @param  bool   $static
  * @return string
  */
 protected function generateMockedMethodDefinition($templateDir, $className, $methodName, $cloneArguments = true, $modifier = 'public', $arguments_decl = '', $arguments_call = '', $reference = '', $callOriginalMethods = false, $static = false)
 {
     if ($static) {
         $templateFile = 'mocked_static_method.tpl';
     } else {
         $templateFile = sprintf('%s_method.tpl', $callOriginalMethods ? 'proxied' : 'mocked');
     }
     $template = new Text_Template($templateDir . $templateFile);
     $template->setVar(array('arguments_decl' => $arguments_decl, 'arguments_call' => $arguments_call, 'arguments_count' => !empty($arguments_call) ? count(explode(',', $arguments_call)) : 0, 'class_name' => $className, 'method_name' => $methodName, 'modifier' => $modifier, 'reference' => $reference, 'clone_arguments' => $cloneArguments ? 'TRUE' : 'FALSE'));
     return $template->render();
 }
Example #8
0
 /**
  * @param int $pageId
  * @param int $languageId
  * @param int $backendUserId
  * @param int $workspaceId
  * @param bool $failOnFailure
  * @return Response
  */
 protected function getFrontendResponse($pageId, $languageId = 0, $backendUserId = 0, $workspaceId = 0, $failOnFailure = TRUE)
 {
     $pageId = (int) $pageId;
     $languageId = (int) $languageId;
     $additionalParameter = '';
     if (!empty($backendUserId)) {
         $additionalParameter .= '&backendUserId=' . (int) $backendUserId;
     }
     if (!empty($workspaceId)) {
         $additionalParameter .= '&workspaceId=' . (int) $workspaceId;
     }
     $arguments = array('documentRoot' => $this->instancePath, 'requestUrl' => 'http://localhost/?id=' . $pageId . '&L=' . $languageId . $additionalParameter);
     $template = new \Text_Template(ORIGINAL_ROOT . 'typo3/sysext/core/Tests/Functional/Fixtures/Frontend/request.tpl');
     $template->setVar(array('arguments' => var_export($arguments, TRUE), 'originalRoot' => ORIGINAL_ROOT));
     $php = \PHPUnit_Util_PHP::factory();
     $response = $php->runJob($template->render());
     $result = json_decode($response['stdout'], TRUE);
     if ($result === FALSE) {
         $this->fail('Frontend Response is empty');
     }
     if ($failOnFailure && $result['status'] === Response::STATUS_Failure) {
         $this->fail('Frontend Response has failure:' . LF . $result['error']);
     }
     $response = new Response($result['status'], $result['content'], $result['error']);
     return $response;
 }
Example #9
0
 /**
  * Generate mail body
  *
  * @return mixed
  */
 protected function generateMessageBody()
 {
     $template = new Template($this->templateFile);
     $template->setVar(['current_date' => date('d.m.Y H:i'), 'form_id' => $this->formId]);
     foreach ($this->fields as $field => $rules) {
         $value = $this->getValue($field);
         $template->setVar([$field => $value]);
     }
     $template->setVar($this->templateData);
     return $template->render();
 }
Example #10
0
 /**
  * Renders this node.
  *
  * @param string  $target
  * @param string  $title
  * @param string  $charset
  * @param integer $lowUpperBound
  * @param integer $highLowerBound
  * @param string  $generator
  */
 public function render($target, $title, $charset = 'UTF-8', $lowUpperBound = 35, $highLowerBound = 70, $generator = '')
 {
     if ($this->yui) {
         $template = new Text_Template(PHP_CodeCoverage_Report_HTML::$templatePath . 'file.html');
         $yuiTemplate = new Text_Template(PHP_CodeCoverage_Report_HTML::$templatePath . 'yui_item.js');
     } else {
         $template = new Text_Template(PHP_CodeCoverage_Report_HTML::$templatePath . 'file_no_yui.html');
     }
     $i = 1;
     $lines = '';
     foreach ($this->codeLines as $line) {
         $css = '';
         if (!isset($this->ignoredLines[$i]) && isset($this->executedLines[$i])) {
             $count = '';
             // Array: Line is executable and was executed.
             // count(Array) = Number of tests that hit this line.
             if (is_array($this->executedLines[$i])) {
                 $color = 'lineCov';
                 $numTests = count($this->executedLines[$i]);
                 $count = sprintf('%8d', $numTests);
                 if ($this->yui) {
                     $buffer = '';
                     $testCSS = '';
                     foreach ($this->executedLines[$i] as $test) {
                         switch ($test['status']) {
                             case 0:
                                 $testCSS = ' class=\\"testPassed\\"';
                                 break;
                             case 1:
                             case 2:
                                 $testCSS = ' class=\\"testIncomplete\\"';
                                 break;
                             case 3:
                                 $testCSS = ' class=\\"testFailure\\"';
                                 break;
                             case 4:
                                 $testCSS = ' class=\\"testError\\"';
                                 break;
                             default:
                                 $testCSS = '';
                         }
                         $buffer .= sprintf('<li%s>%s</li>', $testCSS, addslashes(htmlspecialchars($test['id'])));
                     }
                     if ($numTests > 1) {
                         $header = $numTests . ' tests cover';
                     } else {
                         $header = '1 test covers';
                     }
                     $header .= ' line ' . $i;
                     $yuiTemplate->setVar(array('line' => $i, 'header' => $header, 'tests' => $buffer), FALSE);
                     $this->yuiPanelJS .= $yuiTemplate->render();
                 }
             } else {
                 if ($this->executedLines[$i] == -1) {
                     $color = 'lineNoCov';
                     $count = sprintf('%8d', 0);
                 } else {
                     $color = 'lineDeadCode';
                     $count = '        ';
                 }
             }
             $css = sprintf('<span class="%s">       %s : ', $color, $count);
         }
         $fillup = array_shift($this->codeLinesFillup);
         if ($fillup > 0) {
             $line .= str_repeat(' ', $fillup);
         }
         $lines .= sprintf('<span class="lineNum" id="container%d"><a name="%d"></a>' . '<a href="#%d" id="line%d">%8d</a> </span>%s%s%s' . "\n", $i, $i, $i, $i, $i, !empty($css) ? $css : '                : ', !$this->highlight ? htmlspecialchars($line) : $line, !empty($css) ? '</span>' : '');
         $i++;
     }
     $items = '';
     foreach ($this->classes as $className => $classData) {
         if ($classData['executedLines'] == $classData['executableLines']) {
             $numTestedClasses = 1;
             $testedClassesPercent = 100;
         } else {
             $numTestedClasses = 0;
             $testedClassesPercent = 0;
         }
         $numMethods = 0;
         $numTestedMethods = 0;
         foreach ($classData['methods'] as $method) {
             if ($method['executableLines'] > 0) {
                 $numMethods++;
                 if ($method['executedLines'] == $method['executableLines']) {
                     $numTestedMethods++;
                 }
             }
         }
         $items .= $this->doRenderItem(array('name' => sprintf('<b><a href="#%d">%s</a></b>', $classData['startLine'], $className), 'numClasses' => 1, 'numTestedClasses' => $numTestedClasses, 'testedClassesPercent' => sprintf('%01.2f', $testedClassesPercent), 'numMethods' => $numMethods, 'numTestedMethods' => $numTestedMethods, 'testedMethodsPercent' => PHP_CodeCoverage_Util::percent($numTestedMethods, $numMethods, TRUE), 'numExecutableLines' => $classData['executableLines'], 'numExecutedLines' => $classData['executedLines'], 'executedLinesPercent' => PHP_CodeCoverage_Util::percent($classData['executedLines'], $classData['executableLines'], TRUE)), $lowUpperBound, $highLowerBound);
         foreach ($classData['methods'] as $methodData) {
             if ($methodData['executableLines'] > 0) {
                 if ($methodData['executedLines'] == $methodData['executableLines']) {
                     $numTestedMethods = 1;
                     $testedMethodsPercent = 100;
                 } else {
                     $numTestedMethods = 0;
                     $testedMethodsPercent = 0;
                 }
                 $items .= $this->doRenderItem(array('name' => sprintf('&nbsp;<a href="#%d">%s</a>', $methodData['startLine'], htmlspecialchars($methodData['signature'])), 'numClasses' => '', 'numTestedClasses' => '', 'testedClassesPercent' => '', 'numMethods' => 1, 'numTestedMethods' => $numTestedMethods, 'testedMethodsPercent' => sprintf('%01.2f', $testedMethodsPercent), 'numExecutableLines' => $methodData['executableLines'], 'numExecutedLines' => $methodData['executedLines'], 'executedLinesPercent' => PHP_CodeCoverage_Util::percent($methodData['executedLines'], $methodData['executableLines'], TRUE), 'crap' => PHP_CodeCoverage_Util::crap($methodData['ccn'], PHP_CodeCoverage_Util::percent($methodData['executedLines'], $methodData['executableLines']))), $lowUpperBound, $highLowerBound, 'method_item.html');
             }
         }
     }
     $this->setTemplateVars($template, $title, $charset, $generator);
     $template->setVar(array('lines' => $lines, 'total_item' => $this->renderTotalItem($lowUpperBound, $highLowerBound, FALSE), 'items' => $items, 'yuiPanelJS' => $this->yuiPanelJS));
     $cleanId = PHP_CodeCoverage_Util::getSafeFilename($this->getId());
     $template->renderTo($target . $cleanId . '.html');
     $this->yuiPanelJS = '';
     $this->executedLines = array();
 }
Example #11
0
    /**
     * Generates the test class' source.
     *
     * @param  boolean $verbose
     * @return mixed
     */
    public function generate($verbose = FALSE)
    {
        $class             = new ReflectionClass(
                               $this->inClassName['fullyQualifiedClassName']
                             );
        $methods           = '';
        $incompleteMethods = '';

        foreach ($class->getMethods() as $method) {
            if (!$method->isConstructor() &&
                !$method->isAbstract() &&
                 $method->isPublic() &&
                 $method->getDeclaringClass()->getName() == $this->inClassName['fullyQualifiedClassName']) {
                $assertAnnotationFound = FALSE;

                if (preg_match_all('/@assert(.*)$/Um', $method->getDocComment(), $annotations)) {
                    foreach ($annotations[1] as $annotation) {
                        if (preg_match('/\((.*)\)\s+([^\s]*)\s+(.*)/', $annotation, $matches)) {
                            switch ($matches[2]) {
                                case '==': {
                                    $assertion = 'Equals';
                                }
                                break;

                                case '!=': {
                                    $assertion = 'NotEquals';
                                }
                                break;

                                case '===': {
                                    $assertion = 'Same';
                                }
                                break;

                                case '!==': {
                                    $assertion = 'NotSame';
                                }
                                break;

                                case '>': {
                                    $assertion = 'GreaterThan';
                                }
                                break;

                                case '>=': {
                                    $assertion = 'GreaterThanOrEqual';
                                }
                                break;

                                case '<': {
                                    $assertion = 'LessThan';
                                }
                                break;

                                case '<=': {
                                    $assertion = 'LessThanOrEqual';
                                }
                                break;

                                case 'throws': {
                                    $assertion = 'exception';
                                }
                                break;

                                default: {
                                    throw new PHPUnit_Framework_Exception(
                                      sprintf(
                                        'Token "%s" could not be parsed in @assert annotation.',
                                        $matches[2]
                                      )
                                    );
                                }
                            }

                            if ($assertion == 'exception') {
                                $template = 'TestMethodException';
                            }

                            else if ($assertion == 'Equals' &&
                                     strtolower($matches[3]) == 'true') {
                                $assertion = 'True';
                                $template  = 'TestMethodBool';
                            }

                            else if ($assertion == 'NotEquals' &&
                                     strtolower($matches[3]) == 'true') {
                                $assertion = 'False';
                                $template  = 'TestMethodBool';
                            }

                            else if ($assertion == 'Equals' &&
                                     strtolower($matches[3]) == 'false') {
                                $assertion = 'False';
                                $template  = 'TestMethodBool';
                            }

                            else if ($assertion == 'NotEquals' &&
                                     strtolower($matches[3]) == 'false') {
                                $assertion = 'True';
                                $template  = 'TestMethodBool';
                            }

                            else {
                                $template = 'TestMethod';
                            }

                            if ($method->isStatic()) {
                                $template .= 'Static';
                            }

                            $methodTemplate = new Text_Template(
                              sprintf(
                                '%s%sTemplate%s%s.tpl',

                                dirname(__FILE__),
                                DIRECTORY_SEPARATOR,
                                DIRECTORY_SEPARATOR,
                                $template
                              )
                            );

                            $origMethodName = $method->getName();
                            $methodName     = ucfirst($origMethodName);

                            if (isset($this->methodNameCounter[$methodName])) {
                                $this->methodNameCounter[$methodName]++;
                            } else {
                                $this->methodNameCounter[$methodName] = 1;
                            }

                            if ($this->methodNameCounter[$methodName] > 1) {
                                $methodName .= $this->methodNameCounter[$methodName];
                            }

                            $methodTemplate->setVar(
                              array(
                                'annotation'     => trim($annotation),
                                'arguments'      => $matches[1],
                                'assertion'      => isset($assertion) ? $assertion : '',
                                'expected'       => $matches[3],
                                'origMethodName' => $origMethodName,
                                'className'      => $this->inClassName['fullyQualifiedClassName'],
                                'methodName'     => $methodName
                              )
                            );

                            $methods .= $methodTemplate->render();

                            $assertAnnotationFound = TRUE;
                        }
                    }
                }

                if (!$assertAnnotationFound) {
                    $methodTemplate = new Text_Template(
                      sprintf(
                        '%s%sTemplate%sIncompleteTestMethod.tpl',

                        dirname(__FILE__),
                        DIRECTORY_SEPARATOR,
                        DIRECTORY_SEPARATOR
                      )
                    );

                    $methodTemplate->setVar(
                      array(
                        'methodName' => ucfirst($method->getName())
                      )
                    );

                    $incompleteMethods .= $methodTemplate->render();
                }
            }
        }

        $classTemplate = new Text_Template(
          sprintf(
            '%s%sTemplate%sTestClass.tpl',

            dirname(__FILE__),
            DIRECTORY_SEPARATOR,
            DIRECTORY_SEPARATOR
          )
        );

        if ($this->inSourceFile != '<internal>') {
            $requireClassFile = sprintf(
              "\n\nrequire_once '%s';",

              $this->inSourceFile
            );
        } else {
            $requireClassFile = '';
        }

        if ($this->outClassName['namespace'] != '') {
            $namespace = "\nnamespace " .
                         $this->outClassName['namespace'] . ";\n";
        } else {
            $namespace = '';
        }

        $classTemplate->setVar(
          array(
            'namespace'          => $namespace,
            'namespaceSeparator' => !empty($namespace) ? '\\' : '',
            'className'          => $this->inClassName['className'],
            'testClassName'      => $this->outClassName['className'],
            'requireClassFile'   => $requireClassFile,
            'methods'            => $methods . $incompleteMethods,
            'date'               => date('Y-m-d'),
            'time'               => date('H:i:s')
          )
        );

        if (!$verbose) {
            return $classTemplate->render();
        } else {
            return array(
              'code'       => $classTemplate->render(),
              'incomplete' => empty($methods)
            );
        }
    }
Example #12
0
 /**
  * @param $metaStep
  * @param $substepsBuffer
  * @return string
  */
 protected function renderSubsteps(Meta $metaStep, $substepsBuffer)
 {
     $metaTemplate = new \Text_Template($this->templatePath . 'substeps.html');
     $metaTemplate->setVar(['metaStep' => $metaStep, 'steps' => $substepsBuffer, 'id' => uniqid()]);
     return $metaTemplate->render();
 }
 /**
  * @param  string $wsdlFile
  * @param  string $className
  * @param  array  $methods
  * @param  array  $options
  *
  * @return string
  * @throws PHPUnit_Framework_MockObject_RuntimeException
  */
 public function generateClassFromWsdl($wsdlFile, $className, array $methods = array(), array $options = array())
 {
     if ($this->soapLoaded === null) {
         $this->soapLoaded = extension_loaded('soap');
     }
     if ($this->soapLoaded) {
         $options = array_merge($options, array('cache_wsdl' => WSDL_CACHE_NONE));
         $client = new SoapClient($wsdlFile, $options);
         $_methods = array_unique($client->__getFunctions());
         unset($client);
         sort($_methods);
         $templateDir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Generator' . DIRECTORY_SEPARATOR;
         $methodTemplate = new Text_Template($templateDir . 'wsdl_method.tpl');
         $methodsBuffer = '';
         foreach ($_methods as $method) {
             $nameStart = strpos($method, ' ') + 1;
             $nameEnd = strpos($method, '(');
             $name = substr($method, $nameStart, $nameEnd - $nameStart);
             if (empty($methods) || in_array($name, $methods)) {
                 $args = explode(',', substr($method, $nameEnd + 1, strpos($method, ')') - $nameEnd - 1));
                 $numArgs = count($args);
                 for ($i = 0; $i < $numArgs; $i++) {
                     $args[$i] = substr($args[$i], strpos($args[$i], '$'));
                 }
                 $methodTemplate->setVar(array('method_name' => $name, 'arguments' => join(', ', $args)));
                 $methodsBuffer .= $methodTemplate->render();
             }
         }
         $optionsBuffer = 'array(';
         foreach ($options as $key => $value) {
             $optionsBuffer .= $key . ' => ' . $value;
         }
         $optionsBuffer .= ')';
         $classTemplate = new Text_Template($templateDir . 'wsdl_class.tpl');
         $namespace = '';
         if (strpos($className, '\\') !== false) {
             $parts = explode('\\', $className);
             $className = array_pop($parts);
             $namespace = 'namespace ' . join('\\', $parts) . ';' . "\n\n";
         }
         $classTemplate->setVar(array('namespace' => $namespace, 'class_name' => $className, 'wsdl' => $wsdlFile, 'options' => $optionsBuffer, 'methods' => $methodsBuffer));
         return $classTemplate->render();
     } else {
         throw new PHPUnit_Framework_MockObject_RuntimeException('The SOAP extension is required to generate a mock object ' . 'from WSDL.');
     }
 }
Example #14
0
 /**
  * Handler for 'end run' event.
  *
  */
 protected function endRun()
 {
     $scenarioHeaderTemplate = new \Text_Template($this->templatePath . 'scenario_header.html');
     $status = !$this->failed ? '<span style="color: green">OK</span>' : '<span style="color: red">FAILED</span>';
     $scenarioHeaderTemplate->setVar(array('name' => 'Codeception Results', 'status' => $status, 'time' => round($this->timeTaken, 1)));
     $header = $scenarioHeaderTemplate->render();
     $scenariosTemplate = new \Text_Template($this->templatePath . 'scenarios.html');
     $scenariosTemplate->setVar(array('header' => $header, 'scenarios' => $this->scenarios, 'successfulScenarios' => $this->successful, 'failedScenarios' => $this->failed, 'skippedScenarios' => $this->skipped, 'incompleteScenarios' => $this->incomplete));
     $this->write($scenariosTemplate->render());
 }
Example #15
0
 /**
  * renders the test object to real PHP code
  *
  * @return string
  */
 public function render()
 {
     $nsMappings = Configuration::getInstance()->getNamespaceMappings();
     if ($this->getNamespace() !== null && $this->getNamespace() != "") {
         $nsName = null;
         if (isset($nsMappings[$this->getNamespace()])) {
             $nsName = $nsMappings[$this->getNamespace()];
         } else {
             $nsOriginal = null;
             $nsTester = null;
             foreach ($nsMappings as $nsOrig => $nsTest) {
                 if (0 === strpos($this->getNamespace(), $nsOrig)) {
                     $nsOriginal = $nsOrig;
                     $nsTester = $nsTest;
                     break;
                 }
             }
             if ($nsOriginal !== null && $nsTester !== null) {
                 $nsName = str_replace($nsOriginal, $nsTester, $this->getNamespace());
             }
         }
         if ($nsName !== null) {
             $ns = "\nnamespace " . $nsName . ";";
             $ns .= "\nuse " . $this->getNamespace() . ";";
         } else {
             $ns = "\nnamespace " . $this->getNamespace() . ";";
         }
     } else {
         $ns = "";
     }
     $methods = "";
     foreach ($this->getWriteableTestedMethods() as $testedMethodContent) {
         $methods .= $testedMethodContent . "\n";
     }
     $tpl = new \Text_Template(\PhpUnitTestGenerator\Resource\Helper::getTemplateFileByName($this->getTestClassTemplate()));
     $tpl->setVar(array('namespace' => $ns, 'testClassName' => $this->getClassname(), 'className' => '\\' . $this->getOriginalFullClassName(), 'baseTestClass' => $this->getBaseClass(), 'methods' => $methods, 'constructorArgs' => $this->getConstructorArgs()));
     return $tpl->render();
 }
 public function renderFile($file, array $locals = array())
 {
     $engine = new \Text_Template($file, $this->options['open-delimiter'], $this->options['close-delimiter']);
     $engine->setVar($locals);
     return $engine->render();
 }
 /**
  * @return string
  */
 public function generate()
 {
     $class = new \ReflectionClass($this->inClassName['fullyQualifiedClassName']);
     $methods = '';
     $incompleteMethods = '';
     foreach ($class->getMethods() as $method) {
         if (!$method->isConstructor() && !$method->isAbstract() && $method->isPublic() && $method->getDeclaringClass()->getName() == $this->inClassName['fullyQualifiedClassName']) {
             $assertAnnotationFound = false;
             if (preg_match_all('/@assert(.*)$/Um', $method->getDocComment(), $annotations)) {
                 foreach ($annotations[1] as $annotation) {
                     if (preg_match('/^\\s{0,}(.*)\\s+\\[([!=<>]+|throws)\\]\\s+(.*)\\s{0,}$/', $annotation, $matches)) {
                         if (preg_match('/^\\((.*)\\)$/', $matches[1], $ps)) {
                             $matches[1] = $ps[1];
                             $mode = '';
                         } else {
                             $mode = 'Function';
                         }
                         if (preg_match('/(.*)\\[\\[(.*)\\]\\]$/', $matches[3], $ps)) {
                             $matches[3] = $ps[1];
                             $matches[4] = $ps[2];
                         }
                         switch ($matches[2]) {
                             case '==':
                                 $assertion = 'Equals';
                                 break;
                             case '!=':
                                 $assertion = 'NotEquals';
                                 break;
                             case '===':
                                 $assertion = 'Same';
                                 break;
                             case '!==':
                                 $assertion = 'NotSame';
                                 break;
                             case '>':
                                 $assertion = 'GreaterThan';
                                 break;
                             case '>=':
                                 $assertion = 'GreaterThanOrEqual';
                                 break;
                             case '<':
                                 $assertion = 'LessThan';
                                 break;
                             case '<=':
                                 $assertion = 'LessThanOrEqual';
                                 break;
                             case 'throws':
                                 $assertion = 'exception';
                                 break;
                             default:
                                 // assert ไม่ถูกต้อง
                                 throw new \RuntimeException('assert error : ' . $annotation);
                         }
                         if ($assertion == 'exception') {
                             $template = 'TestMethodException';
                         } elseif ($assertion == 'Equals' && strtolower($matches[3]) == 'true') {
                             $assertion = 'True';
                             $template = 'TestMethodBool';
                         } elseif ($assertion == 'NotEquals' && strtolower($matches[3]) == 'true') {
                             $assertion = 'False';
                             $template = 'TestMethodBool';
                         } elseif ($assertion == 'Equals' && strtolower($matches[3]) == 'false') {
                             $assertion = 'False';
                             $template = 'TestMethodBool';
                         } elseif ($assertion == 'NotEquals' && strtolower($matches[3]) == 'false') {
                             $assertion = 'True';
                             $template = 'TestMethodBool';
                         } else {
                             $template = 'TestMethod';
                         }
                         $template .= $mode;
                         if ($method->isStatic()) {
                             $template .= 'Static';
                         }
                         $methodTemplate = new \Text_Template(sprintf('%s%stemplate%s%s.tpl', __DIR__, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $template));
                         $origMethodName = $method->getName();
                         $methodName = ucfirst($origMethodName);
                         if (isset($this->methodNameCounter[$methodName])) {
                             $this->methodNameCounter[$methodName]++;
                         } else {
                             $this->methodNameCounter[$methodName] = 1;
                         }
                         if ($this->methodNameCounter[$methodName] > 1) {
                             $methodName .= $this->methodNameCounter[$methodName];
                         }
                         $methodTemplate->setVar(array('annotation' => trim($annotation), 'arguments' => $matches[1], 'assertion' => isset($assertion) ? $assertion : '', 'expected' => $matches[3], 'origMethodName' => $origMethodName, 'className' => $this->inClassName['fullyQualifiedClassName'], 'methodName' => $methodName, 'option' => empty($matches[4]) ? '' : str_replace('$this', '$this->object', $matches[4]) . ';'));
                         $methods .= $methodTemplate->render();
                         $assertAnnotationFound = true;
                     } else {
                         // assert ไม่ถูกต้อง
                         throw new \RuntimeException('assert error : ' . $annotation);
                     }
                 }
             }
             if (!$assertAnnotationFound) {
                 $methodTemplate = new \Text_Template(sprintf('%s%stemplate%sIncompleteTestMethod.tpl', __DIR__, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR));
                 $methodTemplate->setVar(array('className' => $this->inClassName['fullyQualifiedClassName'], 'methodName' => ucfirst($method->getName()), 'origMethodName' => $method->getName()));
                 $incompleteMethods .= $methodTemplate->render();
             }
         }
     }
     $classTemplate = new \Text_Template(sprintf('%s%stemplate%sTestClass.tpl', __DIR__, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR));
     // parse setup from class doc
     $documents = $class->getDocComment();
     $setups = array();
     $setupParam = '';
     if (preg_match_all('/@setupParam\\s{1,}(.*)\\s{0,}$/Um', $documents, $annotations)) {
         foreach ($annotations[1] as $annotation) {
             $setupParam = $annotation;
         }
     }
     if (preg_match_all('/@setup\\s{1,}(.*)\\s{0,}$/Um', $documents, $annotations)) {
         foreach ($annotations[1] as $annotation) {
             $setups[] = str_replace('$this', '$this->object', $annotation);
         }
     }
     if ($this->outClassName['namespace'] != '') {
         $namespace = "\nnamespace " . $this->outClassName['namespace'] . ";\n";
     } else {
         $namespace = '';
     }
     if (empty($setups)) {
         // default setup
         $setups[] = '$this->object = new ' . $this->inClassName['className'] . '(' . $setupParam . ')';
     }
     $classTemplate->setVar(array('namespace' => $namespace, 'namespaceSeparator' => !empty($namespace) ? '\\' : '', 'className' => $this->inClassName['className'], 'testClassName' => $this->outClassName['className'], 'methods' => $methods . $incompleteMethods, 'date' => date('Y-m-d'), 'time' => date('H:i:s'), 'setups' => implode("\n", $setups), 'setupParam' => empty($setupParam) ? '' : "({$setupParam})"));
     return $classTemplate->render();
 }
Example #18
0
 /**
  * @param string $templateDir
  * @param string $className
  * @param string $methodName
  * @param bool   $cloneArguments
  * @param string $modifier
  * @param string $arguments_decl
  * @param string $arguments_call
  * @param string $return_type
  * @param string $reference
  * @param bool   $callOriginalMethods
  * @param bool   $static
  *
  * @return string
  */
 private function generateMockedMethodDefinition($templateDir, $className, $methodName, $cloneArguments = true, $modifier = 'public', $arguments_decl = '', $arguments_call = '', $return_type = '', $reference = '', $callOriginalMethods = false, $static = false)
 {
     if ($static) {
         $templateFile = 'mocked_static_method.tpl';
     } else {
         $templateFile = sprintf('%s_method.tpl', $callOriginalMethods ? 'proxied' : 'mocked');
     }
     // Mocked interfaces returning 'self' must explicitly declare the
     // interface name as the return type. See
     // https://bugs.php.net/bug.php?id=70722
     if ($return_type === 'self') {
         $return_type = $className;
     }
     $template = new Text_Template($templateDir . $templateFile);
     $template->setVar(['arguments_decl' => $arguments_decl, 'arguments_call' => $arguments_call, 'return_delim' => $return_type ? ': ' : '', 'return_type' => $return_type, 'arguments_count' => !empty($arguments_call) ? count(explode(',', $arguments_call)) : 0, 'class_name' => $className, 'method_name' => $methodName, 'modifier' => $modifier, 'reference' => $reference, 'clone_arguments' => $cloneArguments ? 'true' : 'false']);
     return $template->render();
 }
 /**
  * @param  string  $templateDir
  * @param  string  $className
  * @param  string  $methodName
  * @param  string  $modifier
  * @param  string  $arguments_decl
  * @param  string  $arguments_call
  * @param  string  $reference
  * @param  boolean $static
  * @return string
  */
 protected static function generateMockedMethodDefinition($templateDir, $className, $methodName, $modifier = 'public', $arguments_decl = '', $arguments_call = '', $reference = '', $static = FALSE)
 {
     if ($static) {
         $template = new Text_Template($templateDir . 'mocked_static_method.tpl');
     } else {
         $template = new Text_Template($templateDir . 'mocked_object_method.tpl');
     }
     $template->setVar(array('arguments_decl' => $arguments_decl, 'arguments_call' => $arguments_call, 'arguments_count' => !empty($arguments_call) ? count(explode(',', $arguments_call)) : 0, 'class_name' => $className, 'method_name' => $methodName, 'modifier' => $modifier, 'reference' => $reference));
     return $template->render();
 }
Example #20
0
 protected function doRenderItem(array $data, $lowUpperBound, $highLowerBound, $template = NULL)
 {
     if ($template === NULL) {
         if ($this instanceof PHP_CodeCoverage_Report_HTML_Node_Directory) {
             $template = 'directory_item.html';
         } else {
             $template = 'file_item.html';
         }
     }
     $itemTemplate = new Text_Template(PHP_CodeCoverage_Report_HTML::$templatePath . $template);
     if ($data['numClasses'] > 0) {
         list($classesColor, $classesLevel) = $this->getColorLevel($data['testedClassesPercent'], $lowUpperBound, $highLowerBound);
         $classesNumber = $data['numTestedClasses'] . ' / ' . $data['numClasses'];
     } else {
         $classesColor = 'snow';
         $classesLevel = 'None';
         $classesNumber = '&nbsp;';
     }
     if ($data['numMethods'] > 0) {
         list($methodsColor, $methodsLevel) = $this->getColorLevel($data['testedMethodsPercent'], $lowUpperBound, $highLowerBound);
         $methodsNumber = $data['numTestedMethods'] . ' / ' . $data['numMethods'];
     } else {
         $methodsColor = 'snow';
         $methodsLevel = 'None';
         $methodsNumber = '&nbsp;';
     }
     list($linesColor, $linesLevel) = $this->getColorLevel($data['executedLinesPercent'], $lowUpperBound, $highLowerBound);
     if ($data['name'] == '<b><a href="#0">*</a></b>') {
         $functions = TRUE;
     } else {
         $functions = FALSE;
     }
     $icon = '';
     if (isset($data['itemClass'])) {
         if ($data['itemClass'] == 'coverDirectory') {
             $icon = '<img alt="directory" src="directory.png"/> ';
         } else {
             if ($data['itemClass'] == 'coverFile') {
                 $icon = '<img alt="file" src="file.png"/> ';
             }
         }
     }
     $itemTemplate->setVar(array('name' => $functions ? 'Functions' : $data['name'], 'icon' => $icon, 'itemClass' => isset($data['itemClass']) ? $data['itemClass'] : 'coverItem', 'classes_color' => $classesColor, 'classes_level' => $functions ? 'None' : $classesLevel, 'classes_tested_width' => floor($data['testedClassesPercent']), 'classes_tested_percent' => !$functions && $data['numClasses'] > 0 ? $data['testedClassesPercent'] . '%' : '&nbsp;', 'classes_not_tested_width' => 100 - floor($data['testedClassesPercent']), 'classes_number' => $functions ? '&nbsp;' : $classesNumber, 'methods_color' => $methodsColor, 'methods_level' => $methodsLevel, 'methods_tested_width' => floor($data['testedMethodsPercent']), 'methods_tested_percent' => $data['numMethods'] > 0 ? $data['testedMethodsPercent'] . '%' : '&nbsp;', 'methods_not_tested_width' => 100 - floor($data['testedMethodsPercent']), 'methods_number' => $methodsNumber, 'lines_color' => $linesColor, 'lines_level' => $linesLevel, 'lines_executed_width' => floor($data['executedLinesPercent']), 'lines_executed_percent' => $data['executedLinesPercent'] . '%', 'lines_not_executed_width' => 100 - floor($data['executedLinesPercent']), 'num_executable_lines' => $data['numExecutableLines'], 'num_executed_lines' => $data['numExecutedLines'], 'crap' => isset($data['crap']) ? $data['crap'] : ''));
     return $itemTemplate->render();
 }
Example #21
0
 /**
  * @param Tombstone $tombstone
  * @param string $class
  *
  * @return string
  */
 private function renderTombstoneItem(Tombstone $tombstone, $class)
 {
     $this->tombstoneTemplate->setVar(array('tombstone' => (string) $tombstone, 'line' => $tombstone->getLine(), 'method' => $tombstone->getMethod(), 'level' => $class));
     return $this->tombstoneTemplate->render();
 }
Example #22
0
 /**
  * @param  PHP_CodeCoverage_Report_Node_File $node
  * @return string
  */
 protected function renderSource(PHP_CodeCoverage_Report_Node_File $node)
 {
     if ($this->yui) {
         $yuiTemplate = new Text_Template($this->templatePath . 'yui_item.js');
     }
     $coverageData = $node->getCoverageData();
     $ignoredLines = $node->getIgnoredLines();
     $testData = $node->getTestData();
     list($codeLines, $fillup) = $this->loadFile($node->getPath());
     $lines = '';
     $yuiPanelJS = '';
     $i = 1;
     foreach ($codeLines as $line) {
         $css = '';
         if (!isset($ignoredLines[$i]) && isset($coverageData[$i])) {
             $count = '';
             $numTests = count($coverageData[$i]);
             if ($coverageData[$i] === NULL) {
                 $color = 'lineDeadCode';
                 $count = '        ';
             } else {
                 if ($numTests == 0) {
                     $color = 'lineNoCov';
                     $count = sprintf('%8d', 0);
                 } else {
                     $color = 'lineCov';
                     $count = sprintf('%8d', $numTests);
                     if ($this->yui) {
                         $buffer = '';
                         $testCSS = '';
                         foreach ($coverageData[$i] as $test) {
                             switch ($testData[$test]) {
                                 case 0:
                                     $testCSS = ' class=\\"testPassed\\"';
                                     break;
                                 case 1:
                                 case 2:
                                     $testCSS = ' class=\\"testIncomplete\\"';
                                     break;
                                 case 3:
                                     $testCSS = ' class=\\"testFailure\\"';
                                     break;
                                 case 4:
                                     $testCSS = ' class=\\"testError\\"';
                                     break;
                                 default:
                                     $testCSS = '';
                             }
                             $buffer .= sprintf('<li%s>%s</li>', $testCSS, addslashes(htmlspecialchars($test)));
                         }
                         if ($numTests > 1) {
                             $header = $numTests . ' tests cover';
                         } else {
                             $header = '1 test covers';
                         }
                         $header .= ' line ' . $i;
                         $yuiTemplate->setVar(array('line' => $i, 'header' => $header, 'tests' => $buffer), FALSE);
                         $yuiPanelJS .= $yuiTemplate->render();
                     }
                 }
             }
             $css = sprintf('<span class="%s">       %s : ', $color, $count);
         }
         $_fillup = array_shift($fillup);
         if ($_fillup > 0) {
             $line .= str_repeat(' ', $_fillup);
         }
         $lines .= sprintf('<span class="lineNum" id="container%d"><a name="%d"></a>' . '<a href="#%d" id="line%d">%8d</a> </span>%s%s%s' . "\n", $i, $i, $i, $i, $i, !empty($css) ? $css : '                : ', !$this->highlight ? htmlspecialchars($line) : $line, !empty($css) ? '</span>' : '');
         $i++;
     }
     return array($lines, $yuiPanelJS);
 }
 /**
  * @param  Text_Template $template
  * @param  array         $data
  * @return string
  */
 protected function renderItemTemplate(Text_Template $template, array $data)
 {
     if (isset($data['numClasses']) && $data['numClasses'] > 0) {
         list($classesColor, $classesLevel) = $this->getColorLevel($data['testedClassesPercent']);
         $classesNumber = $data['numTestedClasses'] . ' / ' . $data['numClasses'];
     } else {
         $classesColor = 'snow';
         $classesLevel = 'None';
         $classesNumber = '&nbsp;';
     }
     if ($data['numMethods'] > 0) {
         list($methodsColor, $methodsLevel) = $this->getColorLevel($data['testedMethodsPercent']);
         $methodsNumber = $data['numTestedMethods'] . ' / ' . $data['numMethods'];
     } else {
         $methodsColor = 'snow';
         $methodsLevel = 'None';
         $methodsNumber = '&nbsp;';
     }
     list($linesColor, $linesLevel) = $this->getColorLevel($data['linesExecutedPercent']);
     $template->setVar(array('itemClass' => isset($data['itemClass']) ? $data['itemClass'] : '', 'icon' => isset($data['icon']) ? $data['icon'] : '', 'crap' => isset($data['crap']) ? $data['crap'] : '', 'name' => $data['name'], 'lines_color' => $linesColor, 'lines_executed_width' => $data['linesExecutedPercent'], 'lines_not_executed_width' => 100 - $data['linesExecutedPercent'], 'lines_executed_percent' => $data['linesExecutedPercentAsString'], 'lines_level' => $linesLevel, 'num_executed_lines' => $data['numExecutedLines'], 'num_executable_lines' => $data['numExecutableLines'], 'methods_color' => $methodsColor, 'methods_tested_width' => $data['testedMethodsPercent'], 'methods_not_tested_width' => 100 - $data['testedMethodsPercent'], 'methods_tested_percent' => $data['testedMethodsPercentAsString'], 'methods_level' => $methodsLevel, 'methods_number' => $methodsNumber, 'classes_color' => $classesColor, 'classes_tested_width' => isset($data['testedClassesPercent']) ? $data['testedClassesPercent'] : '', 'classes_not_tested_width' => isset($data['testedClassesPercent']) ? 100 - $data['testedClassesPercent'] : '', 'classes_tested_percent' => isset($data['testedClassesPercentAsString']) ? $data['testedClassesPercentAsString'] : '', 'classes_level' => $classesLevel, 'classes_number' => $classesNumber));
     return $template->render();
 }
 /**
  * @param int $numDead
  * @param int $total
  *
  * @return string
  */
 private function renderBar($numDead, $total)
 {
     $this->barTemplate->setVar(array('level' => 'success', 'percent' => round($numDead / $total * 100, 2)));
     return $this->barTemplate->render();
 }
Example #25
0
 /**
  * parse a given template name with given hash of key-value pairs
  *
  * @param string $name
  * @param array $hash
  * @return string
  */
 public static function getParsedTemplateByNameAndHash($name, array $hash = array())
 {
     $tpl = new \Text_Template(self::getTemplateFileByName($name));
     $tpl->setVar($hash);
     return $tpl->render();
 }
Example #26
0
 /**
  * Cleans and returns a line. Removes php tag added to make highlight-string
  * work
  * 
  * @param unknown_type $traceline
  * @param unknown_type $relativePosition
  * @param unknown_type $style
  * @return Ambigous <string, mixed>
  */
 protected function getLine($traceline, $relativePosition, $style = 'normal')
 {
     $line = new \Text_Template($this->templateDir() . '/Line.html.dist');
     $code = str_replace(array('<span style="color: #0000BB">&lt;?php&nbsp;</span>', '<code>', '</code>'), '', highlight_string('<?php ' . Backtrace::readLine($traceline['file'], $traceline['line'] + $relativePosition), true));
     $code = preg_replace('/\\n/', '', $code);
     $code = preg_replace('/<span style="color: #0000BB">&lt;\\?php&nbsp;(.*)(<\\/span>+?)/', '$1', $code);
     $line->setVar(array('line' => $traceline['line'] + $relativePosition, 'class' => $style, 'code' => ' ' . $code));
     return $line->render();
 }
Example #27
0
 protected function getCoverageBar($percent)
 {
     $level = $this->getColorLevel($percent);
     $template = new Text_Template($this->templatePath . 'coverage_bar.html', '{{', '}}');
     $template->setVar(array('level' => $level, 'percent' => sprintf('%.2F', $percent)));
     return $template->render();
 }
Example #28
0
 /**
  * Handler for 'end run' event.
  *
  */
 protected function endRun()
 {
     $scenariosTemplate = new Text_Template($this->templatePath . 'scenarios.html');
     $scenariosTemplate->setVar(array('scenarios' => $this->scenarios, 'successfulScenarios' => $this->successful, 'failedScenarios' => $this->failed, 'skippedScenarios' => $this->skipped, 'incompleteScenarios' => $this->incomplete));
     $this->write($scenariosTemplate->render());
 }
Example #29
0
 /**
  * Generates the class' source.
  *
  * @return mixed
  */
 public function generate()
 {
     $methods = '';
     foreach ($this->findTestedMethods() as $method) {
         $methodTemplate = new Text_Template(sprintf('%s%sTemplate%sMethod.tpl', dirname(__FILE__), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR));
         $methodTemplate->setVar(array('methodName' => $method));
         $methods .= $methodTemplate->render();
     }
     $classTemplate = new Text_Template(sprintf('%s%sTemplate%sClass.tpl', dirname(__FILE__), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR));
     $classTemplate->setVar(array('className' => $this->outClassName['fullyQualifiedClassName'], 'methods' => $methods, 'date' => date('Y-m-d'), 'time' => date('H:i:s')));
     return $classTemplate->render();
 }
Example #30
0
 /**
  * Creates the controller and attaches observers to it
  * 
  * @param Request $request
  * @param string $className
  */
 protected function _createController(Request $request, $className)
 {
     $template = new \Text_Template(__DIR__ . DIRECTORY_SEPARATOR . 'Spy' . DIRECTORY_SEPARATOR . 'Controller.php.dist');
     $spyControllerName = 'SpyController' . rand(0, time());
     $template->setVar(array('spyController' => $spyControllerName, 'userController' => $className));
     eval($template->render());
     $this->_currentController = new $spyControllerName($request, $this->getResponse(), $this->getParams());
     foreach ($this->_observers as $observer) {
         $this->_currentController->attach($observer);
     }
     if (!$this->_currentController instanceof ActionController) {
         require_once 'Zend/Controller/Dispatcher/Exception.php';
         throw new DispatcherException('Controller "' . $className . '" is not an instance of Zend_Controller_Action_Interface');
     }
     return $this->_currentController;
 }