Example #1
0
 protected function tearDown()
 {
     xdebug_stop_code_coverage(false);
     $this->clearEntity($this->method);
     xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
     parent::tearDown();
 }
Example #2
0
 /**
  * Launches a test module for web inspection of results
  * @param string $module
  * @return boolean
  */
 function WebLauncher($module)
 {
     jf::$ErrorHandler->UnsetErrorHandler();
     $this->LoadFramework();
     self::$TestSuite = new \PHPUnit_Framework_TestSuite();
     self::$TestFiles[] = $this->ModuleFile($module);
     self::$TestSuite->addTestFile(self::$TestFiles[0]);
     $result = new \PHPUnit_Framework_TestResult();
     $listener = new TestListener();
     $result->addListener($listener);
     $Profiler = new Profiler();
     if (function_exists("xdebug_start_code_coverage")) {
         xdebug_start_code_coverage();
     }
     self::$TestSuite->run($result);
     if (function_exists("xdebug_start_code_coverage")) {
         $Coverage = xdebug_get_code_coverage();
     } else {
         $Coverage = null;
     }
     $Profiler->Stop();
     $listener->Finish();
     $this->OutputResult($result, $Profiler, $Coverage);
     return true;
 }
Example #3
0
/**
 * The main Drush function.
 *
 * - Runs "early" option code, if set (see global options).
 * - Parses the command line arguments, configuration files and environment.
 * - Prepares and executes a Drupal bootstrap, if possible,
 * - Dispatches the given command.
 *
 * function_exists('drush_main') may be used by modules to detect whether
 * they are being called from Drush.  See http://drupal.org/node/1181308
 * and http://drupal.org/node/827478
 *
 * @return mixed
 *   Whatever the given command returns.
 */
function drush_main()
{
    // Load Drush core include files, and parse command line arguments.
    require dirname(__FILE__) . '/includes/preflight.inc';
    if (drush_preflight_prepare() === FALSE) {
        return 1;
    }
    // Start code coverage collection.
    if ($coverage_file = drush_get_option('drush-coverage', FALSE)) {
        drush_set_context('DRUSH_CODE_COVERAGE', $coverage_file);
        xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
        register_shutdown_function('drush_coverage_shutdown');
    }
    // Load the global Drush configuration files, and global Drush commands.
    // Find the selected site based on --root, --uri or cwd
    // Preflight the selected site, and load any configuration and commandfiles associated with it.
    // Select and return the bootstrap class.
    $bootstrap = drush_preflight();
    // Reset our bootstrap phase to the beginning
    drush_set_context('DRUSH_BOOTSTRAP_PHASE', DRUSH_BOOTSTRAP_NONE);
    $return = '';
    if (!drush_get_error()) {
        if ($file = drush_get_option('early', FALSE)) {
            require_once $file;
            $function = 'drush_early_' . basename($file, '.inc');
            if (function_exists($function)) {
                if ($return = $function()) {
                    // If the function returns FALSE, we continue and attempt to bootstrap
                    // as normal. Otherwise, we exit early with the returned output.
                    if ($return === TRUE) {
                        $return = '';
                    }
                }
            }
        } else {
            // Do any necessary preprocessing operations on the command,
            // perhaps handling immediately.
            $command_handled = drush_preflight_command_dispatch();
            if (!$command_handled) {
                $return = $bootstrap->bootstrap_and_dispatch();
            }
        }
    }
    // TODO: Get rid of global variable access here, and just trust
    // the bootstrap object returned from drush_preflight().  This will
    // require some adjustments to Drush bootstrapping.
    // See: https://github.com/drush-ops/drush/pull/1303
    if ($bootstrap = drush_get_bootstrap_object()) {
        $bootstrap->terminate();
    }
    drush_postflight();
    // How strict are we?  If we are very strict, turn 'ok' into 'error'
    // if there are any warnings in the log.
    if ($return == 0 && drush_get_option('strict') > 1 && drush_log_has_errors()) {
        $return = 1;
    }
    // After this point the drush_shutdown function will run,
    // exiting with the correct exit code.
    return $return;
}
Example #4
0
 /**
  * Starts the code coverage
  *
  * @return void
  */
 public static function coverageStart()
 {
     if (!extension_loaded("xdebug")) {
         return;
     }
     xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
 }
Example #5
0
 /**
  * Begin code coverage checks
  *
  * @access public
  * @param ReportInterface $report The report to add information to
  * @return void
  */
 public function start(ReportInterface $report)
 {
     if (function_exists('xdebug_start_code_coverage')) {
         $this->started = TRUE;
         $this->report = $report;
         xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
     }
 }
Example #6
0
 /**
  * Starts code coverage.
  */
 public function start()
 {
     //@see bug https://github.com/facebook/hhvm/issues/4752
     try {
         xdebug_start_code_coverage($this->_config['coverage']);
     } catch (Exception $e) {
     }
 }
 /**
  * Paints the start of a group test. Will also paint
  * the page header and footer if this is the
  * first test. Will stash the size if the first start.
  * @param string $test_name   Name of test that is starting.
  * @param integer $size       Number of test cases starting.
  */
 function paintGroupStart($test_name, $size)
 {
     $this->time = $this->getMicrotime();
     HtmlReporter::paintGroupStart($test_name, $size);
     if (extension_loaded('xdebug')) {
         xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
     }
 }
Example #8
0
 /**
  * Starts gathering the information for code coverage.
  * @param  string
  * @return void
  */
 public static function start($file)
 {
     self::$file = $file;
     xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
     register_shutdown_function(function () {
         register_shutdown_function(array(__CLASS__, 'save'));
     });
 }
Example #9
0
 /**
  * Start collection of code coverage information.
  *
  * @param bool $determineUnusedAndDead
  */
 public function start($determineUnusedAndDead = true)
 {
     if ($determineUnusedAndDead) {
         xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
     } else {
         xdebug_start_code_coverage();
     }
 }
Example #10
0
 public function startCoverage()
 {
     $this->root = getcwd();
     if (!extension_loaded('xdebug')) {
         throw new Exception('Could not load xdebug extension');
     }
     xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
 }
Example #11
0
 public function startCodeCoverage()
 {
     //echo "startCodeCoverage called...\n";
     if (extension_loaded('xdebug')) {
         xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
         //echo "xdebug_start_code_coverage called...\n";
     }
 }
Example #12
0
 /**
  *
  */
 public function __construct()
 {
     if (is_callable("xdebug_start_code_coverage") && $this->getClassFileName()) {
         xdebug_stop_code_coverage();
         xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
     } else {
         echo __METHOD__ . ": Unsupported code coverage.";
     }
 }
 public static function startCodeCoverageAnalysis()
 {
     if (self::isCodeCoverageAnalysisRunning()) {
         return;
     }
     self::clearCodeCoverageReport();
     self::perparePhpIni();
     xdebug_start_code_coverage();
     self::$m_isCodeCoverageAnalysisRunning = true;
 }
Example #14
0
 function generar_layout()
 {
     $selecciones = $this->controlador->get_selecciones();
     echo "<div style='background-color: white; border: 1px solid black; text-align: left; padding: 15px'>";
     try {
         //Se construye un suite por categoria que tenga test seleccionados
         foreach (toba_test_lista_casos::get_categorias() as $categoria) {
             $test = new GroupTest($categoria['nombre']);
             $hay_uno = false;
             foreach (toba_test_lista_casos::get_casos() as $caso) {
                 if ($caso['categoria'] == $categoria['id'] && in_array($caso['id'], $selecciones['casos'])) {
                     $hay_uno = true;
                     require_once $caso['archivo'];
                     $test->addTestCase(new $caso['id']($caso['nombre']));
                 }
             }
             if ($hay_uno) {
                 //--- COBERTURA DE CODIGO (OPCIONAL) ----
                 if (function_exists('xdebug_start_code_coverage')) {
                     xdebug_start_code_coverage();
                 }
                 //-------
                 $test->run(new toba_test_reporter());
                 //--- COBERTURA DE CODIGO (OPCIONAL) ----
                 $arch = 'PHPUnit2/Util/CodeCoverage/Renderer.php';
                 $existe = toba_manejador_archivos::existe_archivo_en_path($arch);
                 if (function_exists('xdebug_start_code_coverage') && $existe) {
                     require_once $arch;
                     $cubiertos = xdebug_get_code_coverage();
                     //Se limpian las referencias a simpletest y a librerias de testing en gral.
                     $archivos = array();
                     foreach (array_keys($cubiertos) as $archivo) {
                         if (!strpos($archivo, 'simpletest') && !strpos($archivo, 'PHPUnit') && !strpos($archivo, 'testing_automatico/') && !strpos($archivo, '/test_')) {
                             $archivos[$archivo] = $cubiertos[$archivo];
                         }
                     }
                     $cc = PHPUnit2_Util_CodeCoverage_Renderer::factory('HTML', array('tests' => $archivos));
                     $path_temp = toba::proyecto()->get_path_temp_www();
                     $salida = $path_temp['real'] . '/cobertura.html';
                     $cc->renderToFile($salida);
                     echo "<a href='{$path_temp['browser']}/cobertura.html' target='_blank'>Ver cobertura de código</a>";
                 }
                 //-------
             }
         }
     } catch (Exception $e) {
         if (method_exists($e, 'mensaje_web')) {
             echo ei_mensaje($e->mensaje_web(), 'error');
         } else {
             echo $e;
         }
     }
     echo '</div><br>';
     $this->dep('lista_archivos')->generar_html();
 }
Example #15
0
 /**
  * Starts gathering the information for code coverage.
  * @param  string
  * @return void
  */
 public static function start($file)
 {
     if (!extension_loaded('xdebug')) {
         throw new \Exception('Code coverage functionality requires Xdebug extension.');
     }
     self::$file = fopen($file, 'a+');
     xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
     register_shutdown_function(function () {
         register_shutdown_function(array(__CLASS__, 'save'));
     });
 }
Example #16
0
 public static function resumeCodeCoverage($force_start = false)
 {
     if (true === self::$coverageStopped || true === $force_start) {
         if (function_exists('xdebug_start_code_coverage')) {
             $started = xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
             self::$coverageStopped = false;
             return $started;
         }
     }
     return;
 }
Example #17
0
 /**
  * Calls a Drush command.
  *
  * This is an exact copy of drush_main from drush.php, but that file
  * cannot be loaded because it produces side effects.
  *
  * @see drush_main
  *
  * @return int|string
  */
 protected static function drushMain()
 {
     $return = '';
     // Start code coverage collection.
     if ($coverage_file = drush_get_option('drush-coverage', false)) {
         drush_set_context('DRUSH_CODE_COVERAGE', $coverage_file);
         xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
         register_shutdown_function('drush_coverage_shutdown');
     }
     /* Set up bootstrap object, so that
      * - 'early' files can bootstrap when needed.
      * - bootstrap constants are available.
      */
     $bootstrap_class = drush_get_option('bootstrap_class', 'Drush\\Boot\\DrupalBoot');
     $bootstrap = new $bootstrap_class();
     drush_set_context('DRUSH_BOOTSTRAP_OBJECT', $bootstrap);
     $bootstrap->preflight();
     // Process initial global options such as --debug.
     _drush_preflight_global_options();
     $return = '';
     drush_preflight();
     if (!drush_get_error()) {
         if ($file = drush_get_option('early', false)) {
             require_once $file;
             $function = 'drush_early_' . basename($file, '.inc');
             if (function_exists($function)) {
                 if ($return = $function()) {
                     // If the function returns FALSE, we continue and attempt to bootstrap
                     // as normal. Otherwise, we exit early with the returned output.
                     if ($return === TRUE) {
                         $return = '';
                     }
                 }
             }
         } else {
             // Do any necessary preprocessing operations on the command,
             // perhaps handling immediately.
             $command_handled = drush_preflight_command_dispatch();
             if (!$command_handled) {
                 $bootstrap = drush_get_context('DRUSH_BOOTSTRAP_OBJECT');
                 $return = $bootstrap->bootstrap_and_dispatch();
             }
         }
     }
     drush_postflight();
     // How strict are we?  If we are very strict, turn 'ok' into 'error'
     // if there are any warnings in the log.
     if ($return == 0 && drush_get_option('strict') > 1 && drush_log_has_errors()) {
         $return = 1;
     }
     // After this point the drush_shutdown function will run,
     // exiting with the correct exit code.
     return $return;
 }
Example #18
0
 public static function init()
 {
     if (array_key_exists('tracefile', $_GET)) {
         exit(highlight_file($_GET['tracefile'], true));
     }
     if (array_key_exists('mirror', $_GET)) {
         exit(self::getCacheFile($_GET['mirror']));
     }
     self::instance()->classes = get_declared_classes();
     self::instance()->functions = get_defined_functions();
     error_reporting(E_ALL | E_STRICT);
     function_exists('xdebug_start_code_coverage') && xdebug_start_code_coverage();
     self::add('Environment', array('_GET' => $_GET, '_POST' => $_POST, '_COOKIE' => $_COOKIE, '_SERVER' => $_SERVER));
 }
Example #19
0
 /**
  * Takes an instance of an object (usually a Collection object) containing test
  * instances. Attaches code coverage filtering to test cases.
  *
  * @see lithium\test\filter\Coverage::collect()
  * @param object $report Instance of Report which is calling apply.
  * @param array $tests The test to apply this filter on
  * @param array $options Options for how code coverage should be applied. These options are
  *              also passed to `Coverage::collect()` to determine how to aggregate results. See
  *              the documentation for `collect()` for further options.  Options affecting this
  *              method are:
  *              -'method': The name of method to attach to, defaults to 'run'.
  * @return object|void Returns the instance of `$tests` with code coverage analysis
  *                     triggers applied.
  */
 public static function apply($report, $tests, array $options = array())
 {
     $defaults = array('method' => 'run');
     $options += $defaults;
     $m = $options['method'];
     $filter = function ($self, $params, $chain) use($report, $options) {
         xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
         $chain->next($self, $params, $chain);
         $results = xdebug_get_code_coverage();
         xdebug_stop_code_coverage();
         $report->collect(__CLASS__, array($self->subject() => $results));
     };
     $tests->invoke('applyFilter', array($m, $filter));
     return $tests;
 }
 public static function start($reportDir = null, $userStory = null)
 {
     if ($reportDir != null) {
         self::initialize($reportDir);
     }
     if (function_exists('xdebug_start_code_coverage')) {
         if (!empty($userStory)) {
             file_put_contents(self::$userStoryFileName, $userStory);
         } else {
             $userStory = self::getUserStoryFromFile();
         }
         if ($userStory != self::CODE_COVERAGE_OFF) {
             xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
         }
     }
 }
 function paintHeader($test_name, $charset = "UTF-8")
 {
     $this->sendNoCacheHeaders();
     header('Content-Type: text/html; Charset=' . $charset);
     print "<html>\n<head>\n<title>{$test_name}</title>\n";
     print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset={$charset}\"/>";
     print "<style type=\"text/css\">\n";
     print $this->_getCss() . "\n";
     print "</style>\n";
     print "</head>\n<body>\n";
     print "<h1>{$test_name}</h1>\n";
     flush();
     if (extension_loaded('xdebug')) {
         xdebug_start_code_coverage(XDEBUG_CC_UNUSED);
     }
 }
Example #22
0
 /**
  * Takes an instance of an object (usually a Collection object) containing test
  * instances. Attaches code coverage filtering to test cases.
  *
  * @see lithium\test\filter\Coverage::collect()
  * @param object $report Instance of Report which is calling apply.
  * @param array $tests The test to apply this filter on
  * @param array $options Options for how code coverage should be applied. These options are
  *              also passed to `Coverage::collect()` to determine how to aggregate results. See
  *              the documentation for `collect()` for further options.  Options affecting this
  *              method are:
  *              -'method': The name of method to attach to, defaults to 'run'.
  * @return object Returns the instance of `$tests` with code coverage analysis
  *                     triggers applied.
  */
 public static function apply($report, $tests, array $options = array())
 {
     $defaults = array('method' => 'run');
     $options += $defaults;
     if (!function_exists('xdebug_start_code_coverage')) {
         $msg = "Xdebug not installed. Please install Xdebug before running code coverage.";
         throw new RuntimeException($msg);
     }
     $filter = function ($self, $params, $chain) use($report, $options) {
         xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
         $chain->next($self, $params, $chain);
         $results = xdebug_get_code_coverage();
         xdebug_stop_code_coverage();
         $report->collect(__CLASS__, array($self->subject() => $results));
     };
     $tests->invoke('applyFilter', array($options['method'], $filter));
     return $tests;
 }
Example #23
0
 /**
  * Configures PHP and environment.
  * @return void
  */
 public static function startup()
 {
     error_reporting(E_ALL | E_STRICT);
     ini_set('display_errors', TRUE);
     ini_set('html_errors', FALSE);
     ini_set('log_errors', FALSE);
     $_SERVER = array_intersect_key($_SERVER, array_flip(array('PHP_SELF', 'SCRIPT_NAME', 'SERVER_ADDR', 'SERVER_SOFTWARE', 'HTTP_HOST', 'DOCUMENT_ROOT', 'OS')));
     $_SERVER['REQUEST_TIME'] = 1234567890;
     $_ENV = array();
     if (PHP_SAPI !== 'cli') {
         header('Content-Type: text/plain; charset=utf-8');
     }
     if (extension_loaded('xdebug')) {
         xdebug_disable();
         xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
         register_shutdown_function(array(__CLASS__, 'prepareSaveCoverage'));
     }
     set_exception_handler(array(__CLASS__, 'exceptionHandler'));
 }
Example #24
0
 /**
  * Starts gathering the information for code coverage.
  * @param  string
  * @return void
  * @throws \LogicException
  */
 public static function start($file)
 {
     if (self::isStarted()) {
         throw new \LogicException('Code coverage collector has been already started.');
     }
     self::$file = fopen($file, 'c+');
     if (defined('PHPDBG_VERSION') && PHP_VERSION_ID >= 70000) {
         phpdbg_start_oplog();
         self::$collector = 'collectPhpDbg';
     } elseif (extension_loaded('xdebug')) {
         xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
         self::$collector = 'collectXdebug';
     } else {
         $alternative = PHP_VERSION_ID >= 70000 ? ' or phpdbg SAPI' : '';
         throw new \LogicException("Code coverage functionality requires Xdebug extension{$alternative}.");
     }
     register_shutdown_function(function () {
         register_shutdown_function([__CLASS__, 'save']);
     });
 }
Example #25
0
 static function bootstrapForTest()
 {
     if (self::$coverage_file_path) {
         xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
     }
     if (self::$coverage_file_path || self::$tests_report_path) {
         register_shutdown_function(__CLASS__ . '::onShutdown');
     }
     if (self::$tests_report_path) {
         self::$start_time = microtime(true);
     }
     assert_options(ASSERT_ACTIVE, 1);
     assert_options(ASSERT_WARNING, 1);
     assert_options(ASSERT_BAIL, 0);
     assert_options(ASSERT_CALLBACK, __CLASS__ . '::throwFromAssertion');
     /*
      * Let's not ignore warnings, but fail with an uncaught exception!
      */
     set_error_handler(__CLASS__ . '::throwFromError');
 }
Example #26
0
 /**
  * @param  array   $codeCoverageInformation
  * @param  boolean $filterTests
  * @return array
  */
 public static function getFilteredCodeCoverage(array $codeCoverageInformation, $filterTests = TRUE)
 {
     if (self::$filter) {
         list($isFilteredCache, $missedFiles) = self::getFileCodeCoverageDisposition($codeCoverageInformation, $filterTests);
         foreach ($codeCoverageInformation as $k => $test) {
             foreach (array_keys($test['files']) as $file) {
                 if (isset($isFilteredCache[$file]) && $isFilteredCache[$file]) {
                     unset($codeCoverageInformation[$k]['files'][$file]);
                 }
             }
             foreach (array_keys($test['dead']) as $file) {
                 if (isset($isFilteredCache[$file]) && $isFilteredCache[$file]) {
                     unset($codeCoverageInformation[$k]['dead'][$file]);
                 }
             }
             foreach (array_keys($test['executable']) as $file) {
                 if (isset($isFilteredCache[$file]) && $isFilteredCache[$file]) {
                     unset($codeCoverageInformation[$k]['executable'][$file]);
                 }
             }
         }
         if (self::$addUncoveredFilesFromWhitelist) {
             foreach (self::$whitelistedFiles as $whitelistedFile) {
                 if (!isset(self::$coveredFiles[$whitelistedFile]) && !self::isFiltered($whitelistedFile, $filterTests, TRUE)) {
                     if (file_exists($whitelistedFile)) {
                         xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
                         include_once $whitelistedFile;
                         $coverage = xdebug_get_code_coverage();
                         xdebug_stop_code_coverage();
                         foreach ($coverage as $file => $fileCoverage) {
                             if (!in_array($file, self::$whitelistedFiles) || isset(self::$coveredFiles[$file])) {
                                 continue;
                             }
                             foreach ($fileCoverage as $line => $flag) {
                                 if ($flag > 0) {
                                     $fileCoverage[$line] = -1;
                                 }
                             }
                             $codeCoverageInformation[] = array('test' => NULL, 'files' => array($file => $fileCoverage));
                             self::addCoveredFile($file);
                         }
                     }
                 }
             }
         }
     }
     return $codeCoverageInformation;
 }
Example #27
0
 public function addNoCoverageFiles()
 {
     echo "Adding files with no coverage information\n";
     // Start by pruning out files we already have information about
     $sql = 'SELECT * FROM files WHERE issource = 1';
     $result = $this->db->query($sql);
     while ($res = $result->fetchArray(SQLITE3_ASSOC)) {
         $key = array_search($res['path'], $this->files);
         if (isset($this->files[$key])) {
             unset($this->files[$key]);
         }
     }
     $codepath = $this->codepath;
     spl_autoload_register(function ($class) use($codepath) {
         $file = str_replace(array('\\', '_'), DIRECTORY_SEPARATOR, $class);
         if (file_exists($codepath . DIRECTORY_SEPARATOR . $file . '.php')) {
             include $codepath . DIRECTORY_SEPARATOR . $file . '.php';
             return true;
         }
         if ($file = stream_resolve_include_path($file . '.php')) {
             include $file;
             return true;
         }
         $fake_class = '<?php class ' . $class . ' {}';
         $fake_class_file = tempnam(sys_get_temp_dir(), 'pyrus_tmp');
         file_put_contents($fake_class_file, $fake_class);
         include $fake_class_file;
         unlink($fake_class_file);
         return true;
     });
     foreach ($this->files as $file) {
         if (empty($file)) {
             continue;
         }
         echo "{$file}\n";
         $id = $this->addFile($file, 1);
         // Figure out of the file has been already inclduded or not
         $included = false;
         $relative_file = substr($file, strlen($this->codepath . DIRECTORY_SEPARATOR), -4);
         // We need to try a few things here to actually find the correct class
         // Foo/Bar.php may mean Foo_Bar Foo\Bar or PEAR2\Foo\Bar
         $class = str_replace('/', '_', $relative_file);
         $ns_class = str_replace('/', '\\', $relative_file);
         $pear2_class = 'PEAR2\\' . $ns_class;
         $classes = array_merge(get_declared_classes(), get_declared_interfaces());
         if (in_array($class, $classes) || in_array($ns_class, $classes) || in_array($pear2_class, $classes)) {
             $included = true;
         }
         // Get basic coverage information on the file
         if ($included === false) {
             xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
             include $file;
             $data = xdebug_get_code_coverage(true);
             $this->lines[$id] = $data[$file];
         } else {
             /*
              * @TODO files that already have been loaded need to have 
              * their missing coverage lines added too
              */
         }
     }
     echo "Done\n";
 }
Example #28
0
 /**
  *    Stashes the name of the test suite. Starts test coverage
  *    if enabled.
  *    @param string $group     Name of test or other label.
  *    @param integer $size     Number of test cases starting.
  *    @access public
  */
 function paintGroupStart($group, $size)
 {
     $this->group = $this->escapeVal($group);
     if ($this->cc) {
         if (extension_loaded('xdebug')) {
             xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
         }
     }
 }
Example #29
0
 /**
  * Runs a TestCase.
  *
  * @param  PHPUnit_Framework_Test $test
  */
 public function run(PHPUnit_Framework_Test $test)
 {
     PHPUnit_Framework_Assert::resetCount();
     $error = FALSE;
     $failure = FALSE;
     $this->startTest($test);
     $errorHandlerSet = FALSE;
     if ($this->convertErrorsToExceptions) {
         $oldErrorHandler = set_error_handler(array('PHPUnit_Util_ErrorHandler', 'handleError'), E_ALL | E_STRICT);
         if ($oldErrorHandler === NULL) {
             $errorHandlerSet = TRUE;
         } else {
             restore_error_handler();
         }
     }
     if (self::$xdebugLoaded === NULL) {
         self::$xdebugLoaded = extension_loaded('xdebug');
         self::$useXdebug = self::$xdebugLoaded;
     }
     $useXdebug = self::$useXdebug && $this->collectCodeCoverageInformation && !$test instanceof PHPUnit_Extensions_SeleniumTestCase;
     if ($useXdebug) {
         xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
     }
     PHPUnit_Util_Timer::start();
     try {
         $test->runBare();
     } catch (PHPUnit_Framework_AssertionFailedError $e) {
         $failure = TRUE;
     } catch (Exception $e) {
         $error = TRUE;
     }
     $time = PHPUnit_Util_Timer::stop();
     if ($useXdebug) {
         $codeCoverage = xdebug_get_code_coverage();
         xdebug_stop_code_coverage();
         $this->appendCodeCoverageInformation($test, $codeCoverage);
     }
     if ($errorHandlerSet === TRUE) {
         restore_error_handler();
     }
     $test->addToAssertionCount(PHPUnit_Framework_Assert::getCount());
     if ($error === TRUE) {
         $this->addError($test, $e, $time);
     } else {
         if ($failure === TRUE) {
             $this->addFailure($test, $e, $time);
         }
     }
     $this->endTest($test, $time);
 }
Example #30
0
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * @package    PHPUnit_Selenium
 * @author     Sebastian Bergmann <*****@*****.**>
 * @copyright  2010-2011 Sebastian Bergmann <*****@*****.**>
 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
 * @link       http://www.phpunit.de/
 * @since      File available since Release 3.2.10
 */
// By default the code coverage files are written to the same directory
// that contains the covered sourcecode files. Use this setting to change
// the default behaviour and set a specific directory to write the files to.
// If you change the default setting, please make sure to also configure
// the same directory in phpunit_coverage.php. Also note that the webserver
// needs write access to the directory.
$GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY'] = FALSE;
if (isset($_COOKIE['PHPUNIT_SELENIUM_TEST_ID']) && !isset($_GET['PHPUNIT_SELENIUM_TEST_ID']) && extension_loaded('xdebug')) {
    $GLOBALS['PHPUNIT_FILTERED_FILES'] = array(__FILE__);
    xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
}