Автор: Sebastian Bergmann (sebastian@phpunit.de)
 /**
  * @param  string  $suiteClassName
  * @param  string  $suiteClassFile
  * @return ReflectionClass
  * @throws PHPUnit_Framework_Exception
  */
 public function load($suiteClassName, $suiteClassFile = '')
 {
     $suiteClassName = str_replace('.php', '', $suiteClassName);
     if (empty($suiteClassFile)) {
         $suiteClassFile = PHPUnit_Util_Filesystem::classNameToFilename($suiteClassName);
     }
     Core_FileReader::addFile($suiteClassFile);
 }
Пример #2
0
 /**
  * Checks if a PHP sourcefile is readable.
  * The sourcefile is loaded through the load() method.
  *
  * @param  string $filename
  * @throws RuntimeException
  */
 public static function checkAndLoad($filename)
 {
     $includePathFilename = PHPUnit_Util_Filesystem::fileExistsInIncludePath($filename);
     if (!$includePathFilename || !is_readable($includePathFilename)) {
         throw new RuntimeException(sprintf('Cannot open file "%s".' . "\n", $filename));
     }
     self::load($includePathFilename);
     return $includePathFilename;
 }
Пример #3
0
 /**
  * @param string $type      The type of concrete Log subclass to use.
  *                          Currently, valid values are 'console',
  *                          'syslog', 'sql', 'file', and 'mcal'.
  * @param string $name      The name of the actually log file, table, or
  *                          other specific store to use. Defaults to an
  *                          empty string, with which the subclass will
  *                          attempt to do something intelligent.
  * @param string $ident     The identity reported to the log system.
  * @param array  $conf      A hash containing any additional configuration
  *                          information that a subclass might need.
  * @param int $maxLevel     Maximum priority level at which to log.
  */
 public function __construct($type, $name = '', $ident = '', $conf = array(), $maxLevel = PEAR_LOG_DEBUG)
 {
     if (PHPUnit_Util_Filesystem::fileExistsInIncludePath('Log.php')) {
         require_once 'Log.php';
     } else {
         throw new RuntimeException('Log is not available.');
     }
     $this->log = Log::factory($type, $name, $ident, $conf, $maxLevel);
 }
Пример #4
0
 function phpunit_autoload($class)
 {
     if (strpos($class, 'PHPUnit_') === 0) {
         $file = str_replace('_', '/', $class) . '.php';
         $file = PHPUnit_Util_Filesystem::fileExistsInIncludePath($file);
         if ($file) {
             require_once $file;
         }
     }
 }
Пример #5
0
 function phpunit_autoload($class)
 {
     if (strpos($class, 'PHPUnit_') === 0) {
         $file = str_replace('_', '/', $class) . '.php';
         $file = PHPUnit_Util_Filesystem::fileExistsInIncludePath($file);
         if ($file) {
             require_once $file;
             PHP_CodeCoverage_Filter::getInstance()->addFileToBlacklist($file, 'PHPUNIT');
         }
     }
 }
 /**
  * @param  string  $suiteClassName
  * @param  string  $suiteClassFile
  * @return ReflectionClass
  * @throws RuntimeException
  */
 public function load($suiteClassName, $suiteClassFile = '')
 {
     $suiteClassName = str_replace('.php', '', $suiteClassName);
     if (empty($suiteClassFile)) {
         $suiteClassFile = PHPUnit_Util_Filesystem::classNameToFilename($suiteClassName);
     }
     if (!class_exists($suiteClassName, FALSE)) {
         PHPUnit_Util_Class::collectStart();
         $filename = PHPUnit_Util_Fileloader::checkAndLoad($suiteClassFile);
         $loadedClasses = PHPUnit_Util_Class::collectEnd();
     }
     if (!class_exists($suiteClassName, FALSE) && !empty($loadedClasses)) {
         $offset = 0 - strlen($suiteClassName);
         foreach ($loadedClasses as $loadedClass) {
             $class = new ReflectionClass($loadedClass);
             if (substr($loadedClass, $offset) === $suiteClassName && $class->getFileName() == $filename) {
                 $suiteClassName = $loadedClass;
                 break;
             }
         }
     }
     if (!class_exists($suiteClassName, FALSE) && !empty($loadedClasses)) {
         $testCaseClass = 'PHPUnit_Framework_TestCase';
         foreach ($loadedClasses as $loadedClass) {
             $class = new ReflectionClass($loadedClass);
             $classFile = $class->getFileName();
             if ($class->isSubclassOf($testCaseClass) && !$class->isAbstract()) {
                 $suiteClassName = $loadedClass;
                 $testCaseClass = $loadedClass;
                 if ($classFile == realpath($suiteClassFile)) {
                     break;
                 }
             }
             if ($class->hasMethod('suite')) {
                 $method = $class->getMethod('suite');
                 if (!$method->isAbstract() && $method->isPublic() && $method->isStatic()) {
                     $suiteClassName = $loadedClass;
                     if ($classFile == realpath($suiteClassFile)) {
                         break;
                     }
                 }
             }
         }
     }
     if (class_exists($suiteClassName, FALSE)) {
         $class = new ReflectionClass($suiteClassName);
         $filePath = $GLOBALS['base_dir'] . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'phpunit' . DIRECTORY_SEPARATOR . $suiteClassFile;
         if ($class->getFileName() == realpath($filePath)) {
             return $class;
         }
     }
     throw new PHPUnit_Framework_Exception(sprintf('Class %s could not be found in %s.', $suiteClassName, $suiteClassFile));
 }
Пример #7
0
 /**
  *
  * @param string $suiteClassName        	
  * @param string $suiteClassFile        	
  *
  * @return ReflectionClass
  *
  * @throws PHPUnit_Framework_Exception
  */
 public function load($suiteClassName, $suiteClassFile = '')
 {
     $suiteClassName = str_replace('.php', '', $suiteClassName);
     if (empty($suiteClassFile)) {
         $suiteClassFile = PHPUnit_Util_Filesystem::classNameToFilename($suiteClassName);
     }
     if (!class_exists($suiteClassName, false)) {
         $loadedClasses = get_declared_classes();
         $filename = PHPUnit_Util_Fileloader::checkAndLoad($suiteClassFile);
         $loadedClasses = array_values(array_diff(get_declared_classes(), $loadedClasses));
     }
     if (!class_exists($suiteClassName, false) && !empty($loadedClasses)) {
         $offset = 0 - strlen($suiteClassName);
         foreach ($loadedClasses as $loadedClass) {
             $class = new ReflectionClass($loadedClass);
             if (substr($loadedClass, $offset) === $suiteClassName && $class->getFileName() == $filename) {
                 $suiteClassName = $loadedClass;
                 break;
             }
         }
     }
     if (!class_exists($suiteClassName, false) && !empty($loadedClasses)) {
         $testCaseClass = 'PHPUnit_Framework_TestCase';
         foreach ($loadedClasses as $loadedClass) {
             $class = new ReflectionClass($loadedClass);
             $classFile = $class->getFileName();
             if ($class->isSubclassOf($testCaseClass) && !$class->isAbstract()) {
                 $suiteClassName = $loadedClass;
                 $testCaseClass = $loadedClass;
                 if ($classFile == realpath($suiteClassFile)) {
                     break;
                 }
             }
             if ($class->hasMethod('suite')) {
                 $method = $class->getMethod('suite');
                 if (!$method->isAbstract() && $method->isPublic() && $method->isStatic()) {
                     $suiteClassName = $loadedClass;
                     if ($classFile == realpath($suiteClassFile)) {
                         break;
                     }
                 }
             }
         }
     }
     if (class_exists($suiteClassName, false)) {
         $class = new ReflectionClass($suiteClassName);
         if ($class->getFileName() == realpath($suiteClassFile)) {
             return $class;
         }
     }
     throw new PHPUnit_Framework_Exception(sprintf("Class '%s' could not be found in '%s'.", $suiteClassName, $suiteClassFile));
 }
Пример #8
0
 /**
  * Loads a PHP sourcefile.
  *
  * @param  string $filename
  * @return mixed
  * @since  Method available since Release 3.0.0
  */
 public static function load($filename)
 {
     $filename = PHPUnit_Util_Filesystem::fileExistsInIncludePath($filename);
     $oldVariableNames = array_keys(get_defined_vars());
     include_once $filename;
     $newVariables = get_defined_vars();
     $newVariableNames = array_diff(array_keys($newVariables), $oldVariableNames);
     foreach ($newVariableNames as $variableName) {
         if ($variableName != 'oldVariableNames') {
             $GLOBALS[$variableName] = $newVariables[$variableName];
         }
     }
     return $filename;
 }
Пример #9
0
 /**
  * Loads a PHP sourcefile.
  *
  * @param  string $filename
  * @return mixed
  * @since  Method available since Release 3.0.0
  */
 public static function load($filename)
 {
     $_filename = PHPUnit_Util_Filesystem::fileExistsInIncludePath($filename);
     if (!$_filename) {
         throw new RuntimeException(sprintf('Cannot open file "%s".' . "\n", $filename));
     }
     $filename = $_filename;
     $oldVariableNames = array_keys(get_defined_vars());
     unset($_filename);
     include_once $filename;
     $newVariables = get_defined_vars();
     $newVariableNames = array_diff(array_keys($newVariables), $oldVariableNames);
     foreach ($newVariableNames as $variableName) {
         if ($variableName != 'oldVariableNames') {
             $GLOBALS[$variableName] = $newVariables[$variableName];
         }
     }
     return $filename;
 }
Пример #10
0
 /**
  * Renders the report.
  *
  * @param  PHPUnit_Framework_TestResult $result
  * @param  string                       $title
  * @param  string                       $target
  * @param  string                       $charset
  * @param  boolean                      $yui
  * @param  boolean                      $highlight
  * @param  integer                      $lowUpperBound
  * @param  integer                      $highLowerBound
  */
 public static function render(PHPUnit_Framework_TestResult $result, $target, $title = '', $charset = 'ISO-8859-1', $yui = TRUE, $highlight = FALSE, $lowUpperBound = 35, $highLowerBound = 70)
 {
     $target = PHPUnit_Util_Filesystem::getDirectory($target);
     self::$templatePath = sprintf('%s%sReport%sTemplate%s', dirname(__FILE__), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR);
     $codeCoverageInformation = $result->getCodeCoverageInformation();
     $files = PHPUnit_Util_CodeCoverage::getSummary($codeCoverageInformation);
     $commonPath = PHPUnit_Util_Filesystem::reducePaths($files);
     $items = self::buildDirectoryStructure($files);
     unset($codeCoverageInformation);
     if ($title == '') {
         $topTestSuite = $result->topTestSuite();
         if ($topTestSuite instanceof PHPUnit_Framework_TestSuite) {
             $title = $topTestSuite->getName();
         }
     }
     unset($result);
     $root = new PHPUnit_Util_Report_Node_Directory($commonPath, NULL);
     self::addItems($root, $items, $files, $yui, $highlight);
     self::copyFiles($target);
     PHPUnit_Util_CodeCoverage::clearSummary();
     $root->render($target, $title, $charset, $lowUpperBound, $highLowerBound);
 }
Пример #11
0
 /**
  * Constructor.
  *
  * @param string $inClassName
  * @param string $inSourceFile
  * @param string $outClassName
  * @param string $outSourceFile
  * @throws RuntimeException
  */
 public function __construct($inClassName, $inSourceFile = '', $outClassName = '', $outSourceFile = '')
 {
     if (class_exists($inClassName)) {
         $reflector = new ReflectionClass($inClassName);
         $inSourceFile = $reflector->getFileName();
         if ($inSourceFile === FALSE) {
             $inSourceFile = '<internal>';
         }
         unset($reflector);
     } else {
         if (empty($inSourceFile)) {
             $possibleFilenames = array($inClassName . '.php', PHPUnit_Util_Filesystem::classNameToFilename($inClassName));
             foreach ($possibleFilenames as $possibleFilename) {
                 if (is_file($possibleFilename)) {
                     $inSourceFile = $possibleFilename;
                 }
             }
         }
         if (empty($inSourceFile)) {
             throw new PHPUnit_Framework_Exception(sprintf('Neither "%s" nor "%s" could be opened.', $possibleFilenames[0], $possibleFilenames[1]));
         }
         if (!is_file($inSourceFile)) {
             throw new PHPUnit_Framework_Exception(sprintf('"%s" could not be opened.', $inSourceFile));
         }
         $inSourceFile = realpath($inSourceFile);
         include_once $inSourceFile;
         if (!class_exists($inClassName)) {
             throw new PHPUnit_Framework_Exception(sprintf('Could not find class "%s" in "%s".', $inClassName, $inSourceFile));
         }
     }
     if (empty($outClassName)) {
         $outClassName = $inClassName . 'Test';
     }
     if (empty($outSourceFile)) {
         $outSourceFile = dirname($inSourceFile) . DIRECTORY_SEPARATOR . $outClassName . '.php';
     }
     parent::__construct($inClassName, $inSourceFile, $outClassName, $outSourceFile);
 }
Пример #12
0
 /**
  * Renders this node.
  *
  * @param string  $target
  * @param string  $title
  * @param string  $charset
  * @param boolean $highlight
  * @param integer $lowUpperBound
  * @param integer $highLowerBound
  * @access public
  */
 public function render($target, $title, $charset = 'ISO-8859-1', $highlight = FALSE, $lowUpperBound = 35, $highLowerBound = 70)
 {
     if ($this->yui) {
         $template = new PHPUnit_Util_Template(PHPUnit_Util_Report::$templatePath . 'file.html');
         $yuiTemplate = new PHPUnit_Util_Template(PHPUnit_Util_Report::$templatePath . 'yui_item.js');
     } else {
         $template = new PHPUnit_Util_Template(PHPUnit_Util_Report::$templatePath . 'file_no_yui.html');
     }
     $i = 1;
     $lines = '';
     $ignore = FALSE;
     foreach ($this->codeLines as $line) {
         if (strpos($line, '@codeCoverageIgnore') !== FALSE) {
             if (strpos($line, '@codeCoverageIgnoreStart') !== FALSE) {
                 $ignore = TRUE;
             } else {
                 if (strpos($line, '@codeCoverageIgnoreEnd') !== FALSE) {
                     $ignore = FALSE;
                 }
             }
         }
         $css = '';
         if (!$ignore && 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 = '';
                     foreach ($this->executedLines[$i] as $test) {
                         if (!isset($test->__liHtml)) {
                             $test->__liHtml = '';
                             if ($test instanceof PHPUnit_Framework_SelfDescribing) {
                                 $testName = $test->toString();
                                 if ($test instanceof PHPUnit_Framework_TestCase) {
                                     switch ($test->getStatus()) {
                                         case PHPUnit_Runner_BaseTestRunner::STATUS_PASSED:
                                             $testCSS = ' class=\\"testPassed\\"';
                                             break;
                                         case PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE:
                                             $testCSS = ' class=\\"testFailure\\"';
                                             break;
                                         case PHPUnit_Runner_BaseTestRunner::STATUS_ERROR:
                                             $testCSS = ' class=\\"testError\\"';
                                             break;
                                         case PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE:
                                         case PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED:
                                             $testCSS = ' class=\\"testIncomplete\\"';
                                             break;
                                         default:
                                             $testCSS = '';
                                     }
                                 }
                             }
                             $test->__liHtml .= sprintf('<li%s>%s</li>', $testCSS, $testName);
                         }
                         $buffer .= $test->__liHtml;
                     }
                     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) {
         $numCalledClasses = $classData['executedLines'] > 0 ? 1 : 0;
         $calledClassesPercent = $numCalledClasses == 1 ? 100 : 0;
         $numCalledMethods = 0;
         $numMethods = count($classData['methods']);
         foreach ($classData['methods'] as $method) {
             if ($method['executedLines'] > 0) {
                 $numCalledMethods++;
             }
         }
         $items .= $this->doRenderItem(array('name' => sprintf('<b><a href="#%d">%s</a></b>', $classData['startLine'], $className), 'numClasses' => 1, 'numCalledClasses' => $numCalledClasses, 'calledClassesPercent' => sprintf('%01.2f', $calledClassesPercent), 'numMethods' => $numMethods, 'numCalledMethods' => $numCalledMethods, 'calledMethodsPercent' => $this->calculatePercent($numCalledMethods, $numMethods), 'numExecutableLines' => $classData['executableLines'], 'numExecutedLines' => $classData['executedLines'], 'executedLinesPercent' => $this->calculatePercent($classData['executedLines'], $classData['executableLines'])), $lowUpperBound, $highLowerBound);
         foreach ($classData['methods'] as $methodName => $methodData) {
             $numCalledMethods = $methodData['executedLines'] > 0 ? 1 : 0;
             $calledMethodsPercent = $numCalledMethods == 1 ? 100 : 0;
             $items .= $this->doRenderItem(array('name' => sprintf('&nbsp;<a href="#%d">%s</a>', $methodData['startLine'], PHPUnit_Util_Class::getMethodSignature(new ReflectionMethod($className, $methodName))), 'numClasses' => '', 'numCalledClasses' => '', 'calledClassesPercent' => '', 'numMethods' => 1, 'numCalledMethods' => $numCalledMethods, 'calledMethodsPercent' => sprintf('%01.2f', $calledMethodsPercent), 'numExecutableLines' => $methodData['executableLines'], 'numExecutedLines' => $methodData['executedLines'], 'executedLinesPercent' => $this->calculatePercent($methodData['executedLines'], $methodData['executableLines'])), $lowUpperBound, $highLowerBound, 'method_item.html');
         }
     }
     $this->setTemplateVars($template, $title, $charset);
     $template->setVar(array('lines' => $lines, 'total_item' => $this->renderTotalItem($lowUpperBound, $highLowerBound, FALSE), 'items' => $items, 'yuiPanelJS' => $this->yuiPanelJS));
     $cleanId = PHPUnit_Util_Filesystem::getSafeFilename($this->getId());
     $template->renderTo($target . $cleanId . '.html');
 }
Пример #13
0
 /**
  * @param string $type      The type of concrete Log subclass to use.
  *                          Currently, valid values are 'console',
  *                          'syslog', 'sql', 'file', and 'mcal'.
  * @param string $name      The name of the actually log file, table, or
  *                          other specific store to use. Defaults to an
  *                          empty string, with which the subclass will
  *                          attempt to do something intelligent.
  * @param string $ident     The identity reported to the log system.
  * @param array  $conf      A hash containing any additional configuration
  *                          information that a subclass might need.
  * @param int $maxLevel     Maximum priority level at which to log.
  */
 public function __construct($type, $name = '', $ident = '', $conf = array(), $maxLevel = PEAR_LOG_DEBUG)
 {
     if (PHPUnit_Util_Filesystem::fileExistsInIncludePath('Log.php')) {
         PHPUnit_Util_Filesystem::collectStart();
         require_once 'Log.php';
         $this->log = Log::factory($type, $name, $ident, $conf, $maxLevel);
         foreach (PHPUnit_Util_Filesystem::collectEnd() as $blacklistedFile) {
             PHPUnit_Util_Filter::addFileToFilter($blacklistedFile, 'PHPUNIT');
         }
     } else {
         throw new RuntimeException('Log is not available.');
     }
 }
Пример #14
0
 protected function updateTicket($ticketId, $newStatus, $message, $resolution)
 {
     if (PHPUnit_Util_Filesystem::fileExistsInIncludePath('XML/RPC2/Client.php')) {
         PHPUnit_Util_Filesystem::collectStart();
         require_once 'XML/RPC2/Client.php';
         $ticket = XML_RPC2_Client::create($this->scheme . '://' . $this->username . ':' . $this->password . '@' . $this->hostpath, array('prefix' => 'ticket.'));
         try {
             $ticketInfo = $ticket->get($ticketId);
         } catch (XML_RPC2_FaultException $e) {
             throw new PHPUnit_Framework_Exception(sprintf("Trac fetch failure: %d: %s\n", $e->getFaultCode(), $e->getFaultString()));
         }
         try {
             printf("Updating Trac ticket #%d, status: %s\n", $ticketId, $newStatus);
             $ticket->update($ticketId, $message, array('status' => $newStatus, 'resolution' => $resolution));
         } catch (XML_RPC2_FaultException $e) {
             throw new PHPUnit_Framework_Exception(sprintf("Trac update failure: %d: %s\n", $e->getFaultCode(), $e->getFaultString()));
         }
         foreach (PHPUnit_Util_Filesystem::collectEnd() as $blacklistedFile) {
             PHPUnit_Util_Filter::addFileToFilter($blacklistedFile, 'PHPUNIT');
         }
     } else {
         throw new PHPUnit_Framework_Exception('XML_RPC2 is not available.');
     }
 }
Пример #15
0
 /**
  * Starts the collection of loaded files.
  *
  * @since  Method available since Release 3.3.0
  */
 public static function collectStart()
 {
     self::$buffer = get_included_files();
 }
Пример #16
0
 function phpunitAutoload($class)
 {
     require_once $this->phpUnitPath . '/PHPUnit/Util/Filesystem.php';
     if (strpos($class, 'PHPUnit_') === 0 || strpos($class, 'PHP_') === 0 || strpos($class, 'Text_') === 0 || strpos($class, 'File_') === 0 || strpos($class, 'Doctrine') === 0 || strpos($class, 'SebastianBergmann') === 0) {
         $file = \PHPUnit_Util_Filesystem::classNameToFilename($class);
         if (file_exists($this->phpUnitPath . '/' . $file)) {
             require_once $file;
         }
     }
 }
Пример #17
0
 /**
  * Constructor.
  *
  * @param  mixed $out
  */
 public function __construct($out = NULL)
 {
     if (PHPUnit_Util_Filesystem::fileExistsInIncludePath('Image/GraphViz.php')) {
         PHPUnit_Util_Filesystem::collectStart();
         require_once 'Image/GraphViz.php';
         $this->graph = new Image_GraphViz(TRUE, array('overlap' => 'scale', 'splines' => 'true', 'sep' => '.1', 'fontsize' => '8'));
         parent::__construct($out);
         foreach (PHPUnit_Util_Filesystem::collectEnd() as $blacklistedFile) {
             PHPUnit_Util_Filter::addFileToFilter($blacklistedFile, 'PHPUNIT');
         }
     } else {
         throw new RuntimeException('Image_GraphViz is not available.');
     }
 }
Пример #18
0
 /**
  * Returns the link to this node.
  *
  * @param  boolean $full
  * @return string
  */
 public function getLink($full)
 {
     if (substr($this->name, -1) == DIRECTORY_SEPARATOR) {
         $name = substr($this->name, 0, -1);
     } else {
         $name = $this->name;
     }
     $cleanId = PHPUnit_Util_Filesystem::getSafeFilename($this->getId());
     if ($full) {
         if ($this->parent !== NULL) {
             $parent = $this->parent->getLink(TRUE) . DIRECTORY_SEPARATOR;
         } else {
             $parent = '';
         }
         return sprintf('%s<a href="%s.html">%s</a>', $parent, $cleanId, $name);
     } else {
         return sprintf('<a href="%s.html">%s</a>', $cleanId, $name);
     }
 }
Пример #19
0
 /**
  * Handles the loading of the PHPUnit_Util_Printer implementation.
  *
  * @param  string $printerClass
  * @param  string $printerFile
  * @return PHPUnit_Util_Printer
  */
 protected function handlePrinter($printerClass, $printerFile = '')
 {
     if (!class_exists($printerClass, FALSE)) {
         if ($printerFile == '') {
             $printerFile = PHPUnit_Util_Filesystem::classNameToFilename($printerClass);
         }
         $printerFile = stream_resolve_include_path($printerFile);
         if ($printerFile) {
             require $printerFile;
         }
     }
     if (class_exists($printerClass, FALSE)) {
         $class = new ReflectionClass($printerClass);
         if ($class->implementsInterface('PHPUnit_Framework_TestListener') && $class->isSubclassOf('PHPUnit_Util_Printer') && $class->isInstantiable()) {
             $printer = $class->newInstance();
         }
     }
     if (!isset($printer)) {
         PHPUnit_TextUI_TestRunner::showError(sprintf('Could not use "%s" as printer.', $printerClass));
     }
     return $printer;
 }
Пример #20
0
 /**
  * @param  array $arguments
  * @since  Method available since Release 3.2.1
  */
 protected function handleConfiguration(array &$arguments)
 {
     if (isset($arguments['configuration']) && !$arguments['configuration'] instanceof PHPUnit_Util_Configuration) {
         $arguments['configuration'] = PHPUnit_Util_Configuration::getInstance($arguments['configuration']);
     }
     $arguments['debug'] = isset($arguments['debug']) ? $arguments['debug'] : FALSE;
     $arguments['filter'] = isset($arguments['filter']) ? $arguments['filter'] : FALSE;
     $arguments['listeners'] = isset($arguments['listeners']) ? $arguments['listeners'] : array();
     $arguments['wait'] = isset($arguments['wait']) ? $arguments['wait'] : FALSE;
     if (isset($arguments['configuration'])) {
         $arguments['configuration']->handlePHPConfiguration();
         $phpunitConfiguration = $arguments['configuration']->getPHPUnitConfiguration();
         if (isset($phpunitConfiguration['backupGlobals']) && !isset($arguments['backupGlobals'])) {
             $arguments['backupGlobals'] = $phpunitConfiguration['backupGlobals'];
         }
         if (isset($phpunitConfiguration['backupStaticAttributes']) && !isset($arguments['backupStaticAttributes'])) {
             $arguments['backupStaticAttributes'] = $phpunitConfiguration['backupStaticAttributes'];
         }
         if (isset($phpunitConfiguration['bootstrap']) && !isset($arguments['bootstrap'])) {
             $arguments['bootstrap'] = $phpunitConfiguration['bootstrap'];
         }
         if (isset($phpunitConfiguration['colors']) && !isset($arguments['colors'])) {
             $arguments['colors'] = $phpunitConfiguration['colors'];
         }
         if (isset($phpunitConfiguration['convertErrorsToExceptions']) && !isset($arguments['convertErrorsToExceptions'])) {
             $arguments['convertErrorsToExceptions'] = $phpunitConfiguration['convertErrorsToExceptions'];
         }
         if (isset($phpunitConfiguration['convertNoticesToExceptions']) && !isset($arguments['convertNoticesToExceptions'])) {
             $arguments['convertNoticesToExceptions'] = $phpunitConfiguration['convertNoticesToExceptions'];
         }
         if (isset($phpunitConfiguration['convertWarningsToExceptions']) && !isset($arguments['convertWarningsToExceptions'])) {
             $arguments['convertWarningsToExceptions'] = $phpunitConfiguration['convertWarningsToExceptions'];
         }
         if (isset($phpunitConfiguration['processIsolation']) && !isset($arguments['processIsolation'])) {
             $arguments['processIsolation'] = $phpunitConfiguration['processIsolation'];
         }
         if (isset($phpunitConfiguration['stopOnFailure']) && !isset($arguments['stopOnFailure'])) {
             $arguments['stopOnFailure'] = $phpunitConfiguration['stopOnFailure'];
         }
         if (isset($phpunitConfiguration['verbose']) && !isset($arguments['verbose'])) {
             $arguments['verbose'] = $phpunitConfiguration['verbose'];
         }
         $groupConfiguration = $arguments['configuration']->getGroupConfiguration();
         if (!empty($groupConfiguration['include']) && !isset($arguments['groups'])) {
             $arguments['groups'] = $groupConfiguration['include'];
         }
         if (!empty($groupConfiguration['exclude']) && !isset($arguments['excludeGroups'])) {
             $arguments['excludeGroups'] = $groupConfiguration['exclude'];
         }
         foreach ($arguments['configuration']->getListenerConfiguration() as $listener) {
             if (!class_exists($listener['class'], FALSE) && $listener['file'] !== '') {
                 $file = PHPUnit_Util_Filesystem::fileExistsInIncludePath($listener['file']);
                 if ($file !== FALSE) {
                     require $file;
                 }
             }
             if (class_exists($listener['class'], FALSE)) {
                 if (count($listener['arguments']) == 0) {
                     $listener = new $listener['class']();
                 } else {
                     $listenerClass = new ReflectionClass($listener['class']);
                     $listener = $listenerClass->newInstanceArgs($listener['arguments']);
                 }
                 if ($listener instanceof PHPUnit_Framework_TestListener) {
                     $arguments['listeners'][] = $listener;
                 }
             }
         }
         $loggingConfiguration = $arguments['configuration']->getLoggingConfiguration();
         if (isset($loggingConfiguration['coverage-html']) && !isset($arguments['reportDirectory'])) {
             if (isset($loggingConfiguration['charset']) && !isset($arguments['reportCharset'])) {
                 $arguments['reportCharset'] = $loggingConfiguration['charset'];
             }
             if (isset($loggingConfiguration['yui']) && !isset($arguments['reportYUI'])) {
                 $arguments['reportYUI'] = $loggingConfiguration['yui'];
             }
             if (isset($loggingConfiguration['highlight']) && !isset($arguments['reportHighlight'])) {
                 $arguments['reportHighlight'] = $loggingConfiguration['highlight'];
             }
             if (isset($loggingConfiguration['lowUpperBound']) && !isset($arguments['reportLowUpperBound'])) {
                 $arguments['reportLowUpperBound'] = $loggingConfiguration['lowUpperBound'];
             }
             if (isset($loggingConfiguration['highLowerBound']) && !isset($arguments['reportHighLowerBound'])) {
                 $arguments['reportHighLowerBound'] = $loggingConfiguration['highLowerBound'];
             }
             $arguments['reportDirectory'] = $loggingConfiguration['coverage-html'];
         }
         if (isset($loggingConfiguration['coverage-clover']) && !isset($arguments['coverageClover'])) {
             $arguments['coverageClover'] = $loggingConfiguration['coverage-clover'];
         }
         if (isset($loggingConfiguration['json']) && !isset($arguments['jsonLogfile'])) {
             $arguments['jsonLogfile'] = $loggingConfiguration['json'];
         }
         if (isset($loggingConfiguration['plain'])) {
             $arguments['listeners'][] = new PHPUnit_TextUI_ResultPrinter($loggingConfiguration['plain'], TRUE);
         }
         if (isset($loggingConfiguration['tap']) && !isset($arguments['tapLogfile'])) {
             $arguments['tapLogfile'] = $loggingConfiguration['tap'];
         }
         if (isset($loggingConfiguration['junit']) && !isset($arguments['junitLogfile'])) {
             $arguments['junitLogfile'] = $loggingConfiguration['junit'];
             if (isset($loggingConfiguration['logIncompleteSkipped']) && !isset($arguments['logIncompleteSkipped'])) {
                 $arguments['logIncompleteSkipped'] = $loggingConfiguration['logIncompleteSkipped'];
             }
         }
         if (isset($loggingConfiguration['story-html']) && !isset($arguments['storyHTMLFile'])) {
             $arguments['storyHTMLFile'] = $loggingConfiguration['story-html'];
         }
         if (isset($loggingConfiguration['story-text']) && !isset($arguments['storyTextFile'])) {
             $arguments['storsTextFile'] = $loggingConfiguration['story-text'];
         }
         if (isset($loggingConfiguration['testdox-html']) && !isset($arguments['testdoxHTMLFile'])) {
             $arguments['testdoxHTMLFile'] = $loggingConfiguration['testdox-html'];
         }
         if (isset($loggingConfiguration['testdox-text']) && !isset($arguments['testdoxTextFile'])) {
             $arguments['testdoxTextFile'] = $loggingConfiguration['testdox-text'];
         }
     }
     if (isset($arguments['configuration'])) {
         $filterConfiguration = $arguments['configuration']->getFilterConfiguration();
         $filter = PHP_CodeCoverage_Filter::getInstance();
         foreach ($filterConfiguration['blacklist']['include']['directory'] as $dir) {
             $filter->addDirectoryToBlacklist($dir['path'], $dir['suffix'], $dir['prefix'], $dir['group']);
         }
         foreach ($filterConfiguration['blacklist']['include']['file'] as $file) {
             $filter->addFileToBlacklist($file);
         }
         foreach ($filterConfiguration['blacklist']['exclude']['directory'] as $dir) {
             $filter->removeDirectoryFromBlacklist($dir['path'], $dir['suffix'], $dir['prefix'], $dir['group']);
         }
         foreach ($filterConfiguration['blacklist']['exclude']['file'] as $file) {
             $filter->removeFileFromBlacklist($file);
         }
         if ((isset($arguments['coverageClover']) || isset($arguments['reportDirectory'])) && extension_loaded('xdebug')) {
             PHP_CodeCoverage::getInstance()->setProcessUncoveredFilesFromWhitelist($filterConfiguration['whitelist']['addUncoveredFilesFromWhitelist']);
             foreach ($filterConfiguration['whitelist']['include']['directory'] as $dir) {
                 $filter->addDirectoryToWhitelist($dir['path'], $dir['suffix'], $dir['prefix']);
             }
             foreach ($filterConfiguration['whitelist']['include']['file'] as $file) {
                 $filter->addFileToWhitelist($file);
             }
             foreach ($filterConfiguration['whitelist']['exclude']['directory'] as $dir) {
                 $filter->removeDirectoryFromWhitelist($dir['path'], $dir['suffix'], $dir['prefix']);
             }
             foreach ($filterConfiguration['whitelist']['exclude']['file'] as $file) {
                 $filter->removeFileFromWhitelist($file);
             }
         }
     }
     $arguments['backupGlobals'] = isset($arguments['backupGlobals']) ? $arguments['backupGlobals'] : NULL;
     $arguments['backupStaticAttributes'] = isset($arguments['backupStaticAttributes']) ? $arguments['backupStaticAttributes'] : NULL;
     $arguments['colors'] = isset($arguments['colors']) ? $arguments['colors'] : FALSE;
     $arguments['convertErrorsToExceptions'] = isset($arguments['convertErrorsToExceptions']) ? $arguments['convertErrorsToExceptions'] : TRUE;
     $arguments['convertNoticesToExceptions'] = isset($arguments['convertNoticesToExceptions']) ? $arguments['convertNoticesToExceptions'] : TRUE;
     $arguments['convertWarningsToExceptions'] = isset($arguments['convertWarningsToExceptions']) ? $arguments['convertWarningsToExceptions'] : TRUE;
     $arguments['excludeGroups'] = isset($arguments['excludeGroups']) ? $arguments['excludeGroups'] : array();
     $arguments['groups'] = isset($arguments['groups']) ? $arguments['groups'] : array();
     $arguments['logIncompleteSkipped'] = isset($arguments['logIncompleteSkipped']) ? $arguments['logIncompleteSkipped'] : FALSE;
     $arguments['processIsolation'] = isset($arguments['processIsolation']) ? $arguments['processIsolation'] : FALSE;
     $arguments['reportCharset'] = isset($arguments['reportCharset']) ? $arguments['reportCharset'] : 'ISO-8859-1';
     $arguments['reportHighlight'] = isset($arguments['reportHighlight']) ? $arguments['reportHighlight'] : FALSE;
     $arguments['reportHighLowerBound'] = isset($arguments['reportHighLowerBound']) ? $arguments['reportHighLowerBound'] : 70;
     $arguments['reportLowUpperBound'] = isset($arguments['reportLowUpperBound']) ? $arguments['reportLowUpperBound'] : 35;
     $arguments['reportYUI'] = isset($arguments['reportYUI']) ? $arguments['reportYUI'] : TRUE;
     $arguments['stopOnFailure'] = isset($arguments['stopOnFailure']) ? $arguments['stopOnFailure'] : FALSE;
     $arguments['verbose'] = isset($arguments['verbose']) ? $arguments['verbose'] : FALSE;
     if ($arguments['filter'] !== FALSE && preg_match('/^[a-zA-Z0-9_]/', $arguments['filter'])) {
         $arguments['filter'] = '/' . $arguments['filter'] . '/';
     }
 }
Пример #21
0
 /**
  * Returns this node's link.
  *
  * @param  boolean $full
  * @return string
  * @access public
  */
 public function getLink($full = FALSE)
 {
     if ($full && $this->parent !== NULL) {
         return sprintf('%s / <a href="%s-test.html">%s</a>', $this->parent->getLink(TRUE), PHPUnit_Util_Filesystem::getSafeFilename($this->getName()), $this->getName());
     } else {
         return sprintf('<a href="%s-test.html">%s</a>', PHPUnit_Util_Filesystem::getSafeFilename($this->getName()), $this->getName());
     }
 }
 /**
  * @param string  $target
  * @param string  $title
  * @param string  $charset
  * @param boolean $highlight
  * @param integer $lowUpperBound
  * @param integer $highLowerBound
  * @access protected
  */
 protected function doRender($target, $title, $charset, $highlight, $lowUpperBound, $highLowerBound)
 {
     $cleanId = PHPUnit_Util_Filesystem::getSafeFilename($this->getId());
     $file = $target . $cleanId . '.html';
     $template = new PHPUnit_Util_Template(PHPUnit_Util_Report::$templatePath . 'directory.html');
     $this->setTemplateVars($template, $title, $charset);
     $totalClassesPercent = $this->getCalledClassesPercent();
     list($totalClassesColor, $totalClassesLevel) = $this->getColorLevel($totalClassesPercent, $lowUpperBound, $highLowerBound);
     $totalMethodsPercent = $this->getCalledMethodsPercent();
     list($totalMethodsColor, $totalMethodsLevel) = $this->getColorLevel($totalMethodsPercent, $lowUpperBound, $highLowerBound);
     $totalLinesPercent = $this->getLineExecutedPercent();
     list($totalLinesColor, $totalLinesLevel) = $this->getColorLevel($totalLinesPercent, $lowUpperBound, $highLowerBound);
     $template->setVar(array('total_item' => $this->renderTotalItem($lowUpperBound, $highLowerBound), 'items' => $this->renderItems($lowUpperBound, $highLowerBound), 'low_upper_bound' => $lowUpperBound, 'high_lower_bound' => $highLowerBound));
     $template->renderTo($file);
 }
Пример #23
0
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * @category   Testing
 * @package    PHPUnit
 * @author     Sebastian Bergmann <*****@*****.**>
 * @copyright  2002-2010 Sebastian Bergmann <*****@*****.**>
 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
 * @link       http://www.phpunit.de/
 * @since      File available since Release 3.0.0
 */
require_once 'PHPUnit/Framework.php';
require_once 'PHPUnit/Util/Filter.php';
require_once 'PHPUnit/Util/Printer.php';
require_once 'PHPUnit/Util/Test.php';
if (PHPUnit_Util_Filesystem::fileExistsInIncludePath('SymfonyComponents/YAML/sfYamlDumper.php')) {
    require_once 'SymfonyComponents/YAML/sfYamlDumper.php';
}
PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
/**
 * A TestListener that generates a logfile of the
 * test execution using the Test Anything Protocol (TAP).
 *
 * @category   Testing
 * @package    PHPUnit
 * @author     Sebastian Bergmann <*****@*****.**>
 * @copyright  2002-2010 Sebastian Bergmann <*****@*****.**>
 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
 * @version    Release: 3.4.15
 * @link       http://www.phpunit.de/
 * @since      Class available since Release 3.0.0
 /**
  * @param  string  $path
  * @param  boolean $useIncludePath
  * @return string
  * @since  Method available since Release 3.5.0
  */
 protected function toAbsolutePath($path, $useIncludePath = FALSE)
 {
     // Check whether the path is already absolute.
     if ($path[0] === '/' || $path[0] === '\\' || strlen($path) > 3 && ctype_alpha($path[0]) && $path[1] === ':' && ($path[2] === '\\' || $path[2] === '/')) {
         return $path;
     }
     // Check whether a stream is used.
     if (strpos($path, '://') !== FALSE) {
         return $path;
     }
     $file = dirname($this->filename) . DIRECTORY_SEPARATOR . $path;
     if ($useIncludePath && !file_exists($file)) {
         $includePathFile = PHPUnit_Util_Filesystem::fileExistsInIncludePath($path);
         if ($includePathFile) {
             $file = $includePathFile;
         }
     }
     return $file;
 }
Пример #25
0
 /**
  * Handles the loading of the PHPUnit_Util_Printer implementation.
  *
  * @param string $printerClass
  * @param string $printerFile
  *
  * @return PHPUnit_Util_Printer
  */
 protected function handlePrinter($printerClass, $printerFile = '')
 {
     if (!class_exists($printerClass, false)) {
         if ($printerFile == '') {
             $printerFile = PHPUnit_Util_Filesystem::classNameToFilename($printerClass);
         }
         $printerFile = stream_resolve_include_path($printerFile);
         if ($printerFile) {
             require $printerFile;
         }
     }
     if (class_exists($printerClass)) {
         $class = new ReflectionClass($printerClass);
         if ($class->implementsInterface('PHPUnit_Framework_TestListener') && $class->isSubclassOf('PHPUnit_Util_Printer') && $class->isInstantiable()) {
             if ($class->isSubclassOf('PHPUnit_TextUI_ResultPrinter')) {
                 return $printerClass;
             }
             $outputStream = isset($this->arguments['stderr']) ? 'php://stderr' : null;
             return $class->newInstance($outputStream);
         }
     }
     $this->showError(sprintf('Could not use "%s" as printer.', $printerClass));
 }
Пример #26
0
 /**
  * @param  PHPUnit_Framework_Test $suite
  * @param  array                  $arguments
  * @return PHPUnit_Framework_TestResult
  */
 public function doRun(PHPUnit_Framework_Test $suite, array $arguments = array())
 {
     $this->handleConfiguration($arguments);
     if (isset($arguments['bootstrap'])) {
         require_once $arguments['bootstrap'];
     }
     if (is_integer($arguments['repeat'])) {
         $suite = new PHPUnit_Extensions_RepeatedTest($suite, $arguments['repeat'], $arguments['filter'], $arguments['groups'], $arguments['excludeGroups']);
     }
     $result = $this->createTestResult();
     if (!$arguments['convertErrorsToExceptions']) {
         $result->convertErrorsToExceptions(FALSE);
     }
     if (!$arguments['convertNoticesToExceptions']) {
         PHPUnit_Framework_Error_Notice::$enabled = FALSE;
     }
     if (!$arguments['convertWarningsToExceptions']) {
         PHPUnit_Framework_Error_Warning::$enabled = FALSE;
     }
     if ($arguments['stopOnFailure']) {
         $result->stopOnFailure(TRUE);
     }
     if ($this->printer === NULL) {
         if (isset($arguments['printer']) && $arguments['printer'] instanceof PHPUnit_Util_Printer) {
             $this->printer = $arguments['printer'];
         } else {
             $this->printer = new PHPUnit_TextUI_ResultPrinter(NULL, $arguments['verbose'], $arguments['ansi']);
         }
     }
     $this->printer->write(PHPUnit_Runner_Version::getVersionString() . "\n\n");
     foreach ($arguments['listeners'] as $listener) {
         $result->addListener($listener);
     }
     $result->addListener($this->printer);
     if (isset($arguments['storyHTMLFile'])) {
         require_once 'PHPUnit/Extensions/Story/ResultPrinter/HTML.php';
         $result->addListener(new PHPUnit_Extensions_Story_ResultPrinter_HTML($arguments['storyHTMLFile']));
     }
     if (isset($arguments['storyTextFile'])) {
         require_once 'PHPUnit/Extensions/Story/ResultPrinter/Text.php';
         $result->addListener(new PHPUnit_Extensions_Story_ResultPrinter_Text($arguments['storyTextFile']));
     }
     if (isset($arguments['testdoxHTMLFile'])) {
         require_once 'PHPUnit/Util/TestDox/ResultPrinter/HTML.php';
         $result->addListener(new PHPUnit_Util_TestDox_ResultPrinter_HTML($arguments['testdoxHTMLFile']));
     }
     if (isset($arguments['testdoxTextFile'])) {
         require_once 'PHPUnit/Util/TestDox/ResultPrinter/Text.php';
         $result->addListener(new PHPUnit_Util_TestDox_ResultPrinter_Text($arguments['testdoxTextFile']));
     }
     if (isset($arguments['graphvizLogfile'])) {
         if (PHPUnit_Util_Filesystem::fileExistsInIncludePath('Image/GraphViz.php')) {
             require_once 'PHPUnit/Util/Log/GraphViz.php';
             $result->addListener(new PHPUnit_Util_Log_GraphViz($arguments['graphvizLogfile']));
         }
     }
     if ((isset($arguments['coverageClover']) || isset($arguments['coverageSource']) || isset($arguments['metricsXML']) || isset($arguments['pmdXML']) || isset($arguments['reportDirectory'])) && extension_loaded('xdebug')) {
         $result->collectCodeCoverageInformation(TRUE);
     }
     if (isset($arguments['jsonLogfile'])) {
         require_once 'PHPUnit/Util/Log/JSON.php';
         $result->addListener(new PHPUnit_Util_Log_JSON($arguments['jsonLogfile']));
     }
     if (isset($arguments['tapLogfile'])) {
         require_once 'PHPUnit/Util/Log/TAP.php';
         $result->addListener(new PHPUnit_Util_Log_TAP($arguments['tapLogfile']));
     }
     if (isset($arguments['xmlLogfile'])) {
         require_once 'PHPUnit/Util/Log/XML.php';
         $result->addListener(new PHPUnit_Util_Log_XML($arguments['xmlLogfile'], $arguments['logIncompleteSkipped']));
     }
     if (isset($arguments['testDatabaseDSN']) && isset($arguments['testDatabaseLogRevision']) && extension_loaded('pdo')) {
         $writeToTestDatabase = TRUE;
     } else {
         $writeToTestDatabase = FALSE;
     }
     if ($writeToTestDatabase) {
         $dbh = PHPUnit_Util_PDO::factory($arguments['testDatabaseDSN']);
         require_once 'PHPUnit/Util/Log/Database.php';
         $dbListener = PHPUnit_Util_Log_Database::getInstance($dbh, $arguments['testDatabaseLogRevision'], isset($arguments['testDatabaseLogInfo']) ? $arguments['testDatabaseLogInfo'] : '');
         $result->addListener($dbListener);
         $result->collectCodeCoverageInformation(TRUE);
     }
     $suite->run($result, $arguments['filter'], $arguments['groups'], $arguments['excludeGroups']);
     $result->flushListeners();
     if ($this->printer instanceof PHPUnit_TextUI_ResultPrinter) {
         $this->printer->printResult($result);
     }
     if (extension_loaded('tokenizer') && extension_loaded('xdebug')) {
         if (isset($arguments['coverageClover'])) {
             $this->printer->write("\nWriting code coverage data to XML file, this may take a moment.");
             require_once 'PHPUnit/Util/Log/CodeCoverage/XML/Clover.php';
             $writer = new PHPUnit_Util_Log_CodeCoverage_XML_Clover($arguments['coverageClover']);
             $writer->process($result);
             $this->printer->write("\n");
         }
         if (isset($arguments['coverageSource'])) {
             $this->printer->write("\nWriting code coverage data to XML files, this may take a moment.");
             require_once 'PHPUnit/Util/Log/CodeCoverage/XML/Source.php';
             $writer = new PHPUnit_Util_Log_CodeCoverage_XML_Source($arguments['coverageSource']);
             $writer->process($result);
             $this->printer->write("\n");
         }
         if ($writeToTestDatabase) {
             $this->printer->write("\nStoring code coverage and software metrics data in database.\nThis may take a moment.");
             require_once 'PHPUnit/Util/Log/CodeCoverage/Database.php';
             $testDb = new PHPUnit_Util_Log_CodeCoverage_Database($dbh);
             $testDb->storeCodeCoverage($result, $dbListener->getRunId(), $arguments['testDatabaseLogRevision'], $arguments['testDatabasePrefix']);
             $this->printer->write("\n");
         }
         if (isset($arguments['metricsXML'])) {
             $this->printer->write("\nWriting metrics report XML file, this may take a moment.");
             require_once 'PHPUnit/Util/Log/Metrics.php';
             $writer = new PHPUnit_Util_Log_Metrics($arguments['metricsXML']);
             $writer->process($result);
             $this->printer->write("\n");
         }
         if (isset($arguments['pmdXML'])) {
             require_once 'PHPUnit/Util/Log/PMD.php';
             $writer = new PHPUnit_Util_Log_PMD($arguments['pmdXML'], $arguments['pmd']);
             $this->printer->write("\nWriting violations report XML file, this may take a moment.");
             $writer->process($result);
             require_once 'PHPUnit/Util/Log/CPD.php';
             $writer = new PHPUnit_Util_Log_CPD(str_replace('.xml', '-cpd.xml', $arguments['pmdXML']));
             $writer->process($result, $arguments['cpdMinLines'], $arguments['cpdMinMatches']);
             $this->printer->write("\n");
         }
         if (isset($arguments['reportDirectory'])) {
             $this->printer->write("\nGenerating code coverage report, this may take a moment.");
             unset($suite);
             PHPUnit_Util_Report::render($result, $arguments['reportDirectory'], $arguments['reportCharset'], $arguments['reportYUI'], $arguments['reportHighlight'], $arguments['reportLowUpperBound'], $arguments['reportHighLowerBound']);
             $this->printer->write("\n");
         }
     }
     $this->pause($arguments['wait']);
     return $result;
 }
Пример #27
0
 /**
  * @param  array $coverage
  * @return array
  * @author Mattis Stordalen Flister <*****@*****.**>
  * @since  Method available since Release 3.2.9
  */
 protected function matchLocalAndRemotePaths(array $coverage)
 {
     $coverageWithLocalPaths = array();
     foreach ($coverage as $originalRemotePath => $data) {
         $remotePath = $originalRemotePath;
         $separator = $this->findDirectorySeparator($remotePath);
         while (!($localpath = PHPUnit_Util_Filesystem::fileExistsInIncludePath($remotePath)) && strpos($remotePath, $separator) !== FALSE) {
             $remotePath = substr($remotePath, strpos($remotePath, $separator) + 1);
         }
         if ($localpath && md5_file($localpath) == $data['md5']) {
             $coverageWithLocalPaths[$localpath] = $data['coverage'];
         }
     }
     return $coverageWithLocalPaths;
 }
Пример #28
0
 /**
  */
 protected static function handleArguments()
 {
     $arguments = array('listGroups' => FALSE, 'syntaxCheck' => TRUE);
     $longOptions = array('ansi', 'bootstrap=', 'configuration=', 'coverage-html=', 'coverage-clover=', 'coverage-source=', 'coverage-xml=', 'exclude-group=', 'filter=', 'group=', 'help', 'list-groups', 'loader=', 'log-graphviz=', 'log-json=', 'log-metrics=', 'log-pmd=', 'log-tap=', 'log-xml=', 'repeat=', 'report=', 'skeleton', 'skeleton-class', 'skeleton-test', 'stop-on-failure', 'story', 'story-html=', 'story-text=', 'tap', 'test-db-dsn=', 'test-db-log-rev=', 'test-db-log-prefix=', 'test-db-log-info=', 'testdox', 'testdox-html=', 'testdox-text=', 'no-syntax-check', 'verbose', 'version', 'wait');
     try {
         $options = PHPUnit_Util_Getopt::getopt($_SERVER['argv'], 'd:', $longOptions);
     } catch (RuntimeException $e) {
         PHPUnit_TextUI_TestRunner::showError($e->getMessage());
     }
     if (isset($options[1][0])) {
         $arguments['test'] = $options[1][0];
     }
     if (isset($options[1][1])) {
         $arguments['testFile'] = $options[1][1];
     } else {
         $arguments['testFile'] = '';
     }
     foreach ($options[0] as $option) {
         switch ($option[0]) {
             case '--ansi':
                 $arguments['ansi'] = TRUE;
                 break;
             case '--bootstrap':
                 $arguments['bootstrap'] = $option[1];
                 break;
             case '--configuration':
                 $arguments['configuration'] = $option[1];
                 break;
             case '--coverage-clover':
             case '--coverage-xml':
                 if (extension_loaded('tokenizer') && extension_loaded('xdebug')) {
                     $arguments['coverageClover'] = $option[1];
                 } else {
                     if (!extension_loaded('tokenizer')) {
                         self::showMissingDependency('The tokenizer extension is not loaded.');
                     } else {
                         self::showMissingDependency('The Xdebug extension is not loaded.');
                     }
                 }
                 break;
             case '--coverage-source':
                 if (extension_loaded('tokenizer') && extension_loaded('xdebug')) {
                     $arguments['coverageSource'] = $option[1];
                 } else {
                     if (!extension_loaded('tokenizer')) {
                         self::showMissingDependency('The tokenizer extension is not loaded.');
                     } else {
                         self::showMissingDependency('The Xdebug extension is not loaded.');
                     }
                 }
                 break;
             case '--coverage-html':
             case '--report':
                 if (extension_loaded('tokenizer') && extension_loaded('xdebug')) {
                     $arguments['reportDirectory'] = $option[1];
                 } else {
                     if (!extension_loaded('tokenizer')) {
                         self::showMissingDependency('The tokenizer extension is not loaded.');
                     } else {
                         self::showMissingDependency('The Xdebug extension is not loaded.');
                     }
                 }
                 break;
             case 'd':
                 $ini = explode('=', $option[1]);
                 if (isset($ini[0])) {
                     if (isset($ini[1])) {
                         ini_set($ini[0], $ini[1]);
                     } else {
                         ini_set($ini[0], TRUE);
                     }
                 }
                 break;
             case '--help':
                 self::showHelp();
                 exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
                 break;
             case '--filter':
                 if (preg_match('/^[a-zA-Z0-9_]/', $option[1])) {
                     $arguments['filter'] = '/' . $option[1] . '/';
                 } else {
                     $arguments['filter'] = $option[1];
                 }
                 break;
             case '--group':
                 $arguments['groups'] = explode(',', $option[1]);
                 break;
             case '--exclude-group':
                 $arguments['excludeGroups'] = explode(',', $option[1]);
                 break;
             case '--list-groups':
                 $arguments['listGroups'] = TRUE;
                 break;
             case '--loader':
                 self::handleLoader($option[1]);
                 break;
             case '--log-json':
                 $arguments['jsonLogfile'] = $option[1];
                 break;
             case '--log-graphviz':
                 if (PHPUnit_Util_Filesystem::fileExistsInIncludePath('Image/GraphViz.php')) {
                     $arguments['graphvizLogfile'] = $option[1];
                 } else {
                     self::showMissingDependency('The Image_GraphViz package is not installed.');
                 }
                 break;
             case '--log-tap':
                 $arguments['tapLogfile'] = $option[1];
                 break;
             case '--log-xml':
                 $arguments['xmlLogfile'] = $option[1];
                 break;
             case '--log-pmd':
                 if (extension_loaded('tokenizer') && extension_loaded('xdebug')) {
                     $arguments['pmdXML'] = $option[1];
                 } else {
                     if (!extension_loaded('tokenizer')) {
                         self::showMissingDependency('The tokenizer extension is not loaded.');
                     } else {
                         self::showMissingDependency('The Xdebug extension is not loaded.');
                     }
                 }
                 break;
             case '--log-metrics':
                 if (extension_loaded('tokenizer') && extension_loaded('xdebug')) {
                     $arguments['metricsXML'] = $option[1];
                 } else {
                     if (!extension_loaded('tokenizer')) {
                         self::showMissingDependency('The tokenizer extension is not loaded.');
                     } else {
                         self::showMissingDependency('The Xdebug extension is not loaded.');
                     }
                 }
                 break;
             case '--repeat':
                 $arguments['repeat'] = (int) $option[1];
                 break;
             case '--stop-on-failure':
                 $arguments['stopOnFailure'] = TRUE;
                 break;
             case '--test-db-dsn':
                 if (extension_loaded('pdo')) {
                     $arguments['testDatabaseDSN'] = $option[1];
                 } else {
                     self::showMissingDependency('The PDO extension is not loaded.');
                 }
                 break;
             case '--test-db-log-rev':
                 if (extension_loaded('pdo')) {
                     $arguments['testDatabaseLogRevision'] = $option[1];
                 } else {
                     self::showMissingDependency('The PDO extension is not loaded.');
                 }
                 break;
             case '--test-db-prefix':
                 if (extension_loaded('pdo')) {
                     $arguments['testDatabasePrefix'] = $option[1];
                 } else {
                     self::showMissingDependency('The PDO extension is not loaded.');
                 }
                 break;
             case '--test-db-log-info':
                 if (extension_loaded('pdo')) {
                     $arguments['testDatabaseLogInfo'] = $option[1];
                 } else {
                     self::showMissingDependency('The PDO extension is not loaded.');
                 }
                 break;
             case '--skeleton':
             case '--skeleton-class':
             case '--skeleton-test':
                 if (isset($arguments['bootstrap'])) {
                     require_once $arguments['bootstrap'];
                 }
                 if ($option[0] == '--skeleton-class') {
                     require_once 'PHPUnit/Util/Skeleton/Class.php';
                     $class = 'PHPUnit_Util_Skeleton_Class';
                 } else {
                     require_once 'PHPUnit/Util/Skeleton/Test.php';
                     $class = 'PHPUnit_Util_Skeleton_Test';
                 }
                 if (isset($arguments['test']) && $arguments['test'] !== FALSE && isset($arguments['testFile'])) {
                     PHPUnit_TextUI_TestRunner::printVersionString();
                     try {
                         $skeleton = new $class($arguments['test'], $arguments['testFile']);
                         $skeleton->write();
                     } catch (Exception $e) {
                         print $e->getMessage() . "\n";
                         printf('Could not skeleton for "%s" to "%s".' . "\n", $skeleton->getOutClassName(), $skeleton->getOutSourceFile());
                         exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT);
                     }
                     printf('Wrote skeleton for "%s" to "%s".' . "\n", $skeleton->getOutClassName(), $skeleton->getOutSourceFile());
                     exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
                 } else {
                     self::showHelp();
                     exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT);
                 }
                 break;
             case '--tap':
                 require_once 'PHPUnit/Util/Log/TAP.php';
                 $arguments['printer'] = new PHPUnit_Util_Log_TAP();
                 break;
             case '--story':
                 require_once 'PHPUnit/Extensions/Story/ResultPrinter/Text.php';
                 $arguments['printer'] = new PHPUnit_Extensions_Story_ResultPrinter_Text();
                 break;
             case '--story-html':
                 $arguments['storyHTMLFile'] = $option[1];
                 break;
             case '--story-text':
                 $arguments['storyTextFile'] = $option[1];
                 break;
             case '--testdox':
                 require_once 'PHPUnit/Util/TestDox/ResultPrinter/Text.php';
                 $arguments['printer'] = new PHPUnit_Util_TestDox_ResultPrinter_Text();
                 break;
             case '--testdox-html':
                 $arguments['testdoxHTMLFile'] = $option[1];
                 break;
             case '--testdox-text':
                 $arguments['testdoxTextFile'] = $option[1];
                 break;
             case '--no-syntax-check':
                 $arguments['syntaxCheck'] = FALSE;
                 break;
             case '--verbose':
                 $arguments['verbose'] = TRUE;
                 break;
             case '--version':
                 PHPUnit_TextUI_TestRunner::printVersionString();
                 exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
                 break;
             case '--wait':
                 $arguments['wait'] = TRUE;
                 break;
         }
     }
     if (!isset($arguments['test']) && isset($arguments['configuration'])) {
         $configuration = new PHPUnit_Util_Configuration($arguments['configuration']);
         $configuration->handlePHPConfiguration();
         $testSuite = $configuration->getTestSuiteConfiguration();
         if ($testSuite !== NULL) {
             $arguments['test'] = $testSuite;
         }
     }
     if (isset($arguments['test']) && is_string($arguments['test']) && substr($arguments['test'], -5, 5) == '.phpt') {
         require_once 'PHPUnit/Extensions/PhptTestCase.php';
         $test = new PHPUnit_Extensions_PhptTestCase($arguments['test']);
         $arguments['test'] = new PHPUnit_Framework_TestSuite();
         $arguments['test']->addTest($test);
     }
     if (!isset($arguments['test']) || isset($arguments['testDatabaseLogRevision']) && !isset($arguments['testDatabaseDSN'])) {
         self::showHelp();
         exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT);
     }
     return $arguments;
 }
Пример #29
0
 /**
  * Handles the loading of the PHPUnit_Runner_TestSuiteLoader implementation.
  *
  * @param  string  $loaderClass
  * @param  string  $loaderFile
  */
 protected function handleLoader($loaderClass, $loaderFile = '')
 {
     if (!class_exists($loaderClass, FALSE)) {
         if ($loaderFile == '') {
             $loaderFile = PHPUnit_Util_Filesystem::classNameToFilename($loaderClass);
         }
         $loaderFile = PHPUnit_Util_Filesystem::fileExistsInIncludePath($loaderFile);
         if ($loaderFile !== FALSE) {
             require $loaderFile;
         }
     }
     if (class_exists($loaderClass, FALSE)) {
         $class = new ReflectionClass($loaderClass);
         if ($class->implementsInterface('PHPUnit_Runner_TestSuiteLoader') && $class->isInstantiable()) {
             $loader = $class->newInstance();
         }
     }
     if (!isset($loader)) {
         PHPUnit_TextUI_TestRunner::showError(sprintf('Could not use "%s" as loader.', $loaderClass));
     }
     return $loader;
 }
Пример #30
0
 /**
  * Returns the dependencies between the classes of this project
  * as GraphViz/DOT markup.
  *
  * @return Image_GraphViz
  * @since  Method available since Release 3.2.2
  */
 public function getDependenciesAsDOT()
 {
     if (PHPUnit_Util_Filesystem::fileExistsInIncludePath('Image/GraphViz.php')) {
         require_once 'Image/GraphViz.php';
     } else {
         throw new RuntimeException('Image_GraphViz is not available.');
     }
     $graph = new Image_GraphViz(TRUE, array('overlap' => 'scale', 'splines' => 'true', 'sep' => '.1', 'fontsize' => '8'));
     foreach (array_keys($this->dependencies) as $className) {
         $graph->addNode($className);
     }
     foreach ($this->dependencies as $from => $dependencies) {
         foreach ($dependencies as $to => $flag) {
             if ($flag === 1) {
                 $graph->addEdge(array($from => $to));
             }
         }
     }
     return $graph;
 }