Пример #1
0
 public function beforeExample(ExampleEvent $event)
 {
     if (!$this->enabled) {
         return;
     }
     $example = $event->getExample();
     $resource = $example->getSpecification()->getResource();
     $this->coverage->filter()->setWhitelistedFiles([]);
     $this->coverage->filter()->addFileToWhitelist($resource->getSrcFilename());
     $this->coverage->start($resource->getSrcClassname());
 }
Пример #2
0
 /**
  * Creates test runner instance.
  *
  * @param string        $rootPath      The absolute path to the root folder of the test suite.
  * @param ResultPrinter $resultPrinter Result printer.
  * @throws \Exception
  */
 public function __construct($rootPath, ResultPrinter $resultPrinter)
 {
     if (!is_dir($rootPath)) {
         throw new \Exception("{$rootPath} is not a directory");
     }
     $this->rootPath = $rootPath;
     $this->resultPrinter = $resultPrinter;
     try {
         $this->coverage = new \PHP_CodeCoverage();
         $this->coverage->filter()->addDirectoryToWhitelist($rootPath);
     } catch (\PHP_CodeCoverage_Exception $e) {
         // can't collect coverage
     }
 }
 /**
  * @param CodeCoverageMonitor  $codeCoverageMonitor,
  * @param CodeCoverageReporter $codeCoverageReporter,
  * @param string[]             $config
  */
 public function __construct(CodeCoverageMonitor $codeCoverageMonitor, CodeCoverageReporter $codeCoverageReporter, $config)
 {
     $this->codeCoverageMonitor = $codeCoverageMonitor;
     $this->codeCoverageReporter = $codeCoverageReporter;
     $this->reportFolder = $config['report_folder'];
     $codeCoverageMonitor->filter()->addDirectoryToWhitelist($config['context_folder']);
 }
Пример #4
0
 /**
  * @covers PHP_CodeCoverage::performUnexecutedCoveredCodeCheck
  * @expectedException PHP_CodeCoverage_CoveredCodeNotExecutedException
  */
 public function testAppendThrowsExceptionIfUsedCodeWasNotExecuted()
 {
     $this->coverage->filter()->addDirectoryToWhitelist(TEST_FILES_PATH);
     $this->coverage->setCheckForUnexecutedCoveredCode(true);
     $data = [TEST_FILES_PATH . 'BankAccount.php' => [29 => -1, 31 => -1]];
     $linesToBeCovered = [TEST_FILES_PATH . 'BankAccount.php' => [29, 31]];
     $linesToBeUsed = [TEST_FILES_PATH . 'BankAccount.php' => [22, 24]];
     $this->coverage->append($data, 'File1.php', true, $linesToBeCovered, $linesToBeUsed);
 }
Пример #5
0
    /**
     * @param  PHP_CodeCoverage $coverage
     * @param  string           $target
     * @return string
     */
    public function process(PHP_CodeCoverage $coverage, $target = null)
    {
        $filter = $coverage->filter();
        $output = sprintf('<?php
$coverage = new PHP_CodeCoverage;
$coverage->setData(%s);
$coverage->setTests(%s);

$filter = $coverage->filter();
$filter->setWhitelistedFiles(%s);

return $coverage;', var_export($coverage->getData(true), 1), var_export($coverage->getTests(), 1), var_export($filter->getWhitelistedFiles(), 1));
        if ($target !== null) {
            return file_put_contents($target, $output);
        } else {
            return $output;
        }
    }
Пример #6
0
function __begin_coverage()
{
    global $__coverage;
    if (isset($__coverage)) {
        return;
    }
    if (!getenv("TEST_COVERAGE")) {
        return;
    }
    require_once "PHP/CodeCoverage.php";
    require_once "PHP/CodeCoverage/Driver.php";
    require_once "PHP/CodeCoverage/Driver/Xdebug.php";
    require_once "PHP/CodeCoverage/Filter.php";
    require_once "PHP/CodeCoverage/Util.php";
    require_once "File/Iterator/Facade.php";
    require_once "File/Iterator/Factory.php";
    require_once "File/Iterator.php";
    $__coverage = new PHP_CodeCoverage();
    $__coverage->start('test');
    $__coverage->filter()->addDirectoryToWhitelist(realpath(dirname(__FILE__) . "/../Modyllic"));
    register_shutdown_function('__end_coverage');
}
Пример #7
0
 /**
  * Runs a TestCase.
  *
  * @param  PHPUnit_Framework_Test $test
  */
 public function run(PHPUnit_Framework_Test $test)
 {
     PHPUnit_Framework_Assert::resetCount();
     $error = FALSE;
     $failure = FALSE;
     $incomplete = FALSE;
     $skipped = 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->codeCoverage !== NULL && !$test instanceof PHPUnit_Extensions_SeleniumTestCase && !$test instanceof PHPUnit_Framework_Warning;
     if ($useXdebug) {
         // We need to blacklist test source files when no whitelist is used.
         if (!$this->codeCoverage->filter()->hasWhitelist()) {
             $classes = PHPUnit_Util_Class::getHierarchy(get_class($test), TRUE);
             foreach ($classes as $class) {
                 $this->codeCoverage->filter()->addFileToBlacklist($class->getFileName());
             }
         }
         $this->codeCoverage->start($test);
     }
     PHP_Timer::start();
     try {
         if (!$test instanceof PHPUnit_Framework_Warning && $this->strictMode && extension_loaded('pcntl') && class_exists('PHP_Invoker')) {
             switch ($test->getSize()) {
                 case PHPUnit_Util_Test::SMALL:
                     $_timeout = $this->timeoutForSmallTests;
                     break;
                 case PHPUnit_Util_Test::MEDIUM:
                     $_timeout = $this->timeoutForMediumTests;
                     break;
                 case PHPUnit_Util_Test::LARGE:
                     $_timeout = $this->timeoutForLargeTests;
                     break;
             }
             $invoker = new PHP_Invoker();
             $invoker->invoke(array($test, 'runBare'), array(), $_timeout);
         } else {
             $test->runBare();
         }
     } catch (PHPUnit_Framework_AssertionFailedError $e) {
         $failure = TRUE;
         if ($e instanceof PHPUnit_Framework_IncompleteTestError) {
             $incomplete = TRUE;
         } else {
             if ($e instanceof PHPUnit_Framework_SkippedTestError) {
                 $skipped = TRUE;
             }
         }
     } catch (Exception $e) {
         $error = TRUE;
     }
     $time = PHP_Timer::stop();
     $test->addToAssertionCount(PHPUnit_Framework_Assert::getCount());
     if ($this->strictMode && $test->getNumAssertions() == 0) {
         $incomplete = TRUE;
     }
     if ($useXdebug) {
         try {
             $this->codeCoverage->stop(!$incomplete && !$skipped);
         } catch (PHP_CodeCoverage_Exception $cce) {
             $error = TRUE;
             if (!isset($e)) {
                 $e = $cce;
             }
         }
     }
     if ($errorHandlerSet === TRUE) {
         restore_error_handler();
     }
     if ($error === TRUE) {
         $this->addError($test, $e, $time);
     } else {
         if ($failure === TRUE) {
             $this->addFailure($test, $e, $time);
         } else {
             if ($this->strictMode && $test->getNumAssertions() == 0) {
                 $this->addFailure($test, new PHPUnit_Framework_IncompleteTestError('This test did not perform any assertions'), $time);
             } else {
                 if ($this->strictMode && $test->hasOutput()) {
                     $this->addFailure($test, new PHPUnit_Framework_OutputError(sprintf('This test printed output: %s', $test->getActualOutput())), $time);
                 }
             }
         }
     }
     $this->endTest($test, $time);
 }
Пример #8
0
     $coverage = new PHP_CodeCoverage();
     $emitter->on('runner.start', function () use($coverage) {
         $coverage->filter()->addDirectoryToWhitelist(__DIR__ . '/src');
         $coverage->filter()->removeFileFromWhitelist(__DIR__ . '/src/Dsl.php');
         $coverage->start('peridot');
     });
     $emitter->on('runner.end', function () use($coverage) {
         $coverage->stop();
         $writer = new PHP_CodeCoverage_Report_HTML();
         $writer->process($coverage, __DIR__ . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'report');
     });
 }
 if ($codeCoverage == 'clover' && $shouldCover) {
     $coverage = new PHP_CodeCoverage();
     $emitter->on('runner.start', function () use($coverage) {
         $coverage->filter()->addDirectoryToWhitelist(__DIR__ . '/src');
         $coverage->filter()->removeFileFromWhitelist(__DIR__ . '/src/Dsl.php');
         $coverage->start('peridot');
     });
     $emitter->on('runner.end', function () use($coverage) {
         $coverage->stop();
         $writer = new PHP_CodeCoverage_Report_Clover();
         $writer->process($coverage, __DIR__ . DIRECTORY_SEPARATOR . 'build' . DIRECTORY_SEPARATOR . 'logs' . DIRECTORY_SEPARATOR . 'clover.xml');
     });
 }
 $emitter->on('peridot.start', function (Environment $env) use(&$coverage) {
     $definition = $env->getDefinition();
     $definition->option("banner", null, InputOption::VALUE_REQUIRED, "Custom banner text");
     $definition->getArgument('path')->setDefault('specs');
 });
 /**
Пример #9
0
 /**
  * Main method.
  */
 public static function main()
 {
     $input = new ezcConsoleInput();
     $input->registerOption(new ezcConsoleOption('', 'clover', ezcConsoleInput::TYPE_STRING));
     $input->registerOption(new ezcConsoleOption('', 'html', ezcConsoleInput::TYPE_STRING));
     $input->registerOption(new ezcConsoleOption('', 'blacklist', ezcConsoleInput::TYPE_STRING, array(), TRUE));
     $input->registerOption(new ezcConsoleOption('', 'whitelist', ezcConsoleInput::TYPE_STRING, array(), TRUE));
     $input->registerOption(new ezcConsoleOption('', 'merge', ezcConsoleInput::TYPE_NONE, FALSE));
     $input->registerOption(new ezcConsoleOption('h', 'help', ezcConsoleInput::TYPE_NONE, NULL, FALSE, '', '', array(), array(), FALSE, FALSE, TRUE));
     $input->registerOption(new ezcConsoleOption('v', 'version', ezcConsoleInput::TYPE_NONE, NULL, FALSE, '', '', array(), array(), FALSE, FALSE, TRUE));
     try {
         $input->process();
     } catch (ezcConsoleOptionException $e) {
         print $e->getMessage() . "\n";
         exit(1);
     }
     if ($input->getOption('help')->value) {
         self::showHelp();
         exit(0);
     } else {
         if ($input->getOption('version')->value) {
             self::printVersionString();
             exit(0);
         }
     }
     $arguments = $input->getArguments();
     $clover = $input->getOption('clover')->value;
     $html = $input->getOption('html')->value;
     $blacklist = $input->getOption('blacklist')->value;
     $whitelist = $input->getOption('whitelist')->value;
     $merge = $input->getOption('merge')->value;
     if (count($arguments) == 1) {
         self::printVersionString();
         $coverage = new PHP_CodeCoverage();
         $filter = $coverage->filter();
         if (empty($whitelist)) {
             $c = new ReflectionClass('ezcBase');
             $filter->addDirectoryToBlacklist(dirname($c->getFileName()));
             $c = new ReflectionClass('ezcConsoleInput');
             $filter->addDirectoryToBlacklist(dirname($c->getFileName()));
             foreach ($blacklist as $item) {
                 if (is_dir($item)) {
                     $filter->addDirectoryToBlacklist($item);
                 } else {
                     if (is_file($item)) {
                         $filter->addFileToBlacklist($item);
                     }
                 }
             }
         } else {
             foreach ($whitelist as $item) {
                 if (is_dir($item)) {
                     $filter->addDirectoryToWhitelist($item);
                 } else {
                     if (is_file($item)) {
                         $filter->addFileToWhitelist($item);
                     }
                 }
             }
         }
         if (!$merge) {
             $coverage->start('phpcov');
             require $arguments[0];
             $coverage->stop();
         } else {
             $facade = new File_Iterator_Facade();
             $result = $facade->getFilesAsArray($arguments[0], '.cov');
             foreach ($files as $file) {
                 $coverage->merge(unserialize(file_get_contents($file)));
             }
         }
         if ($clover) {
             $writer = new PHP_CodeCoverage_Report_Clover();
             $writer->process($coverage, $clover);
         }
         if ($html) {
             $writer = new PHP_CodeCoverage_Report_HTML();
             $writer->process($coverage, $html);
         }
     } else {
         self::showHelp();
         exit(1);
     }
 }
Пример #10
0
 /**
  * Merges the data from another instance of PHP_CodeCoverage.
  *
  * @param PHP_CodeCoverage $that
  */
 public function merge(PHP_CodeCoverage $that)
 {
     $this->filter->setBlacklistedFiles(array_merge($this->filter->getBlacklistedFiles(), $that->filter()->getBlacklistedFiles()));
     $this->filter->setWhitelistedFiles(array_merge($this->filter->getWhitelistedFiles(), $that->filter()->getWhitelistedFiles()));
     foreach ($that->data as $file => $lines) {
         if (!isset($this->data[$file])) {
             if (!$this->filter->isFiltered($file)) {
                 $this->data[$file] = $lines;
             }
             continue;
         }
         foreach ($lines as $line => $data) {
             if ($data !== NULL) {
                 if (!isset($this->data[$file][$line])) {
                     $this->data[$file][$line] = $data;
                 } else {
                     $this->data[$file][$line] = array_unique(array_merge($this->data[$file][$line], $data));
                 }
             }
         }
     }
     $this->tests = array_merge($this->tests, $that->getTests());
 }
Пример #11
0
 public function __construct(\PHP_CodeCoverage $phpCoverage)
 {
     $this->phpCodeCoverage = $phpCoverage ? $phpCoverage : new \PHP_CodeCoverage();
     $this->filter = $this->phpCodeCoverage->filter();
 }
Пример #12
0
 /**
  * Merges the data from another instance of PHP_CodeCoverage.
  *
  * @param PHP_CodeCoverage $that
  */
 public function merge(PHP_CodeCoverage $that)
 {
     foreach ($that->getData() as $file => $lines) {
         if (!isset($this->data[$file])) {
             if (!$that->filter()->isFiltered($file)) {
                 $this->data[$file] = $lines;
             }
             continue;
         }
         foreach ($lines as $line => $data) {
             if ($data !== null) {
                 if (!isset($this->data[$file][$line])) {
                     $this->data[$file][$line] = $data;
                 } else {
                     $this->data[$file][$line] = array_unique(array_merge($this->data[$file][$line], $data));
                 }
             }
         }
     }
     $this->tests = array_merge($this->tests, $that->getTests());
 }
Пример #13
0
                $files = array_merge($files, Tests::getFromCategory($argument));
            }
        }
    }
}
if (count($files) === 0) {
    $files = Tests::getAll();
}
switch ($command) {
    case 'list':
        Testrunner::search($files);
        break;
    case 'check':
        if (in_array('coverage', $options)) {
            $coverage = new PHP_CodeCoverage();
            $coverage->filter()->addDirectoryToWhitelist('src');
            $coverage->start('Testrunner');
        }
        $result = Testrunner::compare($files);
        if (in_array('coverage', $options)) {
            $coverage->stop();
            $writer = new PHP_CodeCoverage_Report_Clover();
            $writer->process($coverage, 'runner.xml');
            echo "\nCoverage saved as runner.xml\n\n";
        }
        if (!$result) {
            echo "Testrunner failed, please fix or rebase before building or deploying!\n\n";
            if (in_array('show', $options)) {
                echo file_get_contents('runner.log') . "\n\n";
                echo "Done!\n\n";
            }
Пример #14
0
 if ($codeCoverage == 'html' && $shouldCover) {
     $coverage = new PHP_CodeCoverage();
     $emitter->on('runner.start', function () use($coverage) {
         $coverage->filter()->addFileToBlacklist(__DIR__ . '/src/Dsl.php');
         $coverage->start('peridot');
     });
     $emitter->on('runner.end', function () use($coverage) {
         $coverage->stop();
         $writer = new PHP_CodeCoverage_Report_HTML();
         $writer->process($coverage, __DIR__ . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'report');
     });
 }
 if ($codeCoverage == 'clover' && $shouldCover) {
     $coverage = new PHP_CodeCoverage();
     $emitter->on('runner.start', function () use($coverage) {
         $coverage->filter()->addFileToBlacklist(__DIR__ . '/src/Dsl.php');
         $coverage->start('peridot');
     });
     $emitter->on('runner.end', function () use($coverage) {
         $coverage->stop();
         $writer = new PHP_CodeCoverage_Report_Clover();
         $writer->process($coverage, __DIR__ . DIRECTORY_SEPARATOR . 'build' . DIRECTORY_SEPARATOR . 'logs' . DIRECTORY_SEPARATOR . 'clover.xml');
     });
 }
 $emitter->on('peridot.start', function (Environment $env) use(&$coverage) {
     $definition = $env->getDefinition();
     $definition->option("banner", null, InputOption::VALUE_REQUIRED, "Custom banner text");
     $definition->getArgument('path')->setDefault('specs');
 });
 /**
  * Demonstrate registering a custom reporter via peridot config
Пример #15
0
 * with this program;  If not, see <http://www.gnu.org/licenses/>.
 */
require_once __DIR__ . '/../../vendor/autoload.php';
$php_code_coverage = null;
$php_code_coverage_db = null;
if (getenv('PHP_CODE_COVERAGE')) {
    $php_code_coverage_db = file(getenv('PHP_CODE_COVERAGE'), FILE_IGNORE_NEW_LINES);
    $php_code_coverage_db_tmp = [];
    foreach ($php_code_coverage_db as $entry) {
        $entry = explode('=', $entry, 2);
        $php_code_coverage_db_tmp[$entry[0]] = unserialize($entry[1]);
    }
    $php_code_coverage_db = $php_code_coverage_db_tmp;
    unset($php_code_coverage_db_tmp);
    $php_code_coverage = new PHP_CodeCoverage();
    $php_code_coverage_filter = $php_code_coverage->filter();
    $php_code_coverage_filter->addFileToBlacklist(__FILE__);
    foreach ($php_code_coverage_db as $entry) {
        $php_code_coverage_filter->addFileToWhitelist($entry['fullname']);
    }
    $php_code_coverage->start(basename(getenv('PHP_CODE_COVERAGE')));
    register_shutdown_function(function ($php_code_coverage, $php_code_coverage_db) {
        $php_code_coverage->stop();
        foreach ($php_code_coverage->getData(true) as $file => $coverage) {
            foreach ($coverage as $line => $id) {
                if (!isset($php_code_coverage_db[strtolower($file)]['coverage'][$line]) || !is_array($php_code_coverage_db[strtolower($file)]['coverage'][$line])) {
                    $php_code_coverage_db[strtolower($file)]['coverage'][$line] = [];
                }
                $id = !is_array($id) ? [$id] : $id;
                $php_code_coverage_db[strtolower($file)]['coverage'][$line] = array_unique(array_merge($id, $php_code_coverage_db[strtolower($file)]['coverage'][$line]));
            }
Пример #16
0
 /**
  * Main method.
  */
 public static function main()
 {
     $input = new ezcConsoleInput();
     $input->registerOption(new ezcConsoleOption('', 'clover', ezcConsoleInput::TYPE_STRING));
     $input->registerOption(new ezcConsoleOption('', 'html', ezcConsoleInput::TYPE_STRING));
     $input->registerOption(new ezcConsoleOption('', 'php', ezcConsoleInput::TYPE_STRING));
     $input->registerOption(new ezcConsoleOption('', 'text', ezcConsoleInput::TYPE_STRING));
     $input->registerOption(new ezcConsoleOption('', 'blacklist', ezcConsoleInput::TYPE_STRING, array(), TRUE));
     $input->registerOption(new ezcConsoleOption('', 'whitelist', ezcConsoleInput::TYPE_STRING, array(), TRUE));
     $input->registerOption(new ezcConsoleOption('', 'merge', ezcConsoleInput::TYPE_NONE, FALSE));
     $input->registerOption(new ezcConsoleOption('', 'add-uncovered', ezcConsoleInput::TYPE_NONE, FALSE));
     $input->registerOption(new ezcConsoleOption('', 'process-uncovered', ezcConsoleInput::TYPE_NONE, FALSE));
     $input->registerOption(new ezcConsoleOption('h', 'help', ezcConsoleInput::TYPE_NONE, NULL, FALSE, '', '', array(), array(), FALSE, FALSE, TRUE));
     $input->registerOption(new ezcConsoleOption('v', 'version', ezcConsoleInput::TYPE_NONE, NULL, FALSE, '', '', array(), array(), FALSE, FALSE, TRUE));
     try {
         $input->process();
     } catch (ezcConsoleOptionException $e) {
         print $e->getMessage() . "\n";
         exit(1);
     }
     if ($input->getOption('help')->value) {
         self::showHelp();
         exit(0);
     } else {
         if ($input->getOption('version')->value) {
             self::printVersionString();
             exit(0);
         }
     }
     $arguments = $input->getArguments();
     $clover = $input->getOption('clover')->value;
     $html = $input->getOption('html')->value;
     $php = $input->getOption('php')->value;
     $text = $input->getOption('text')->value;
     $blacklist = $input->getOption('blacklist')->value;
     $whitelist = $input->getOption('whitelist')->value;
     $addUncovered = $input->getOption('add-uncovered')->value;
     $processUncovered = $input->getOption('process-uncovered')->value;
     $merge = $input->getOption('merge')->value;
     if (count($arguments) == 1) {
         self::printVersionString();
         $coverage = new PHP_CodeCoverage();
         $filter = $coverage->filter();
         if (empty($whitelist)) {
             $c = new ReflectionClass('ezcBase');
             $filter->addDirectoryToBlacklist(dirname($c->getFileName()));
             $c = new ReflectionClass('ezcConsoleInput');
             $filter->addDirectoryToBlacklist(dirname($c->getFileName()));
             foreach ($blacklist as $item) {
                 if (is_dir($item)) {
                     $filter->addDirectoryToBlacklist($item);
                 } else {
                     if (is_file($item)) {
                         $filter->addFileToBlacklist($item);
                     }
                 }
             }
         } else {
             $coverage->setAddUncoveredFilesFromWhitelist($addUncovered);
             $coverage->setProcessUncoveredFilesFromWhitelist($processUncovered);
             foreach ($whitelist as $item) {
                 if (is_dir($item)) {
                     $filter->addDirectoryToWhitelist($item);
                 } else {
                     if (is_file($item)) {
                         $filter->addFileToWhitelist($item);
                     }
                 }
             }
         }
         if (!$merge) {
             $coverage->start('phpcov');
             require $arguments[0];
             $coverage->stop();
         } else {
             $finder = new Symfony\Component\Finder\Finder();
             $finder->in($arguments[0])->name('*.cov');
             foreach ($finder as $file) {
                 $coverage->merge(unserialize(file_get_contents($file->getRealpath())));
             }
         }
         if ($clover) {
             $writer = new PHP_CodeCoverage_Report_Clover();
             $writer->process($coverage, $clover);
         }
         if ($html) {
             $writer = new PHP_CodeCoverage_Report_HTML();
             $writer->process($coverage, $html);
         }
         if ($php) {
             $writer = new PHP_CodeCoverage_Report_PHP();
             $writer->process($coverage, $php);
         }
         if ($text) {
             $writer = new PHP_CodeCoverage_Report_Text();
             $writer->process($coverage, $text);
         }
     } else {
         self::showHelp();
         exit(1);
     }
 }
Пример #17
0
<?php

require __DIR__ . '/../vendor/autoload.php';
$coverage = new PHP_CodeCoverage();
$coverage->filter()->addDirectoryToBlacklist(__DIR__ . '../vendor/');
$coverage->start('behat-api-test');
// Initialize the Kohana application
include __DIR__ . '/index.php';
$coverage->stop();
$file = __DIR__ . '/../coverage/behat-' . uniqid() . '.xml';
$writer = new PHP_CodeCoverage_Report_Clover();
$writer->process($coverage, $file);
Пример #18
0
 /**
  * Runs a TestCase.
  *
  * @param PHPUnit_Framework_Test $test
  */
 public function run(PHPUnit_Framework_Test $test)
 {
     PHPUnit_Framework_Assert::resetCount();
     $error = false;
     $failure = false;
     $incomplete = false;
     $risky = false;
     $skipped = 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();
         }
     }
     $collectCodeCoverage = $this->codeCoverage !== null && !$test instanceof PHPUnit_Extensions_SeleniumTestCase && !$test instanceof PHPUnit_Framework_Warning;
     if ($collectCodeCoverage) {
         // We need to blacklist test source files when no whitelist is used.
         if (!$this->codeCoverage->filter()->hasWhitelist()) {
             $classes = $this->getHierarchy(get_class($test), true);
             foreach ($classes as $class) {
                 $this->codeCoverage->filter()->addFileToBlacklist($class->getFileName());
             }
         }
         $this->codeCoverage->start($test);
     }
     PHP_Timer::start();
     try {
         if (!$test instanceof PHPUnit_Framework_Warning && $this->beStrictAboutTestSize && extension_loaded('pcntl') && class_exists('PHP_Invoker')) {
             switch ($test->getSize()) {
                 case PHPUnit_Util_Test::SMALL:
                     $_timeout = $this->timeoutForSmallTests;
                     break;
                 case PHPUnit_Util_Test::MEDIUM:
                     $_timeout = $this->timeoutForMediumTests;
                     break;
                 case PHPUnit_Util_Test::LARGE:
                     $_timeout = $this->timeoutForLargeTests;
                     break;
             }
             $invoker = new PHP_Invoker();
             $invoker->invoke(array($test, 'runBare'), array(), $_timeout);
         } else {
             $test->runBare();
         }
     } catch (PHPUnit_Framework_AssertionFailedError $e) {
         $failure = true;
         if ($e instanceof PHPUnit_Framework_RiskyTestError) {
             $risky = true;
         } elseif ($e instanceof PHPUnit_Framework_IncompleteTestError) {
             $incomplete = true;
         } elseif ($e instanceof PHPUnit_Framework_SkippedTestError) {
             $skipped = true;
         }
     } catch (PHPUnit_Framework_Exception $e) {
         $error = true;
     } catch (Exception $e) {
         $e = new PHPUnit_Framework_ExceptionWrapper($e);
         $error = true;
     }
     $time = PHP_Timer::stop();
     $test->addToAssertionCount(PHPUnit_Framework_Assert::getCount());
     if ($this->beStrictAboutTestsThatDoNotTestAnything && $test->getNumAssertions() == 0) {
         $risky = true;
     }
     if ($collectCodeCoverage) {
         $append = !$risky && !$incomplete && !$skipped;
         $linesToBeCovered = array();
         $linesToBeUsed = array();
         if ($append && $test instanceof PHPUnit_Framework_TestCase) {
             $linesToBeCovered = PHPUnit_Util_Test::getLinesToBeCovered(get_class($test), $test->getName(false));
             $linesToBeUsed = PHPUnit_Util_Test::getLinesToBeUsed(get_class($test), $test->getName(false));
         }
         try {
             $this->codeCoverage->stop($append, $linesToBeCovered, $linesToBeUsed);
         } catch (PHP_CodeCoverage_Exception_UnintentionallyCoveredCode $cce) {
             $this->addFailure($test, new PHPUnit_Framework_UnintentionallyCoveredCodeError('This test executed code that is not listed as code to be covered or used:' . PHP_EOL . $cce->getMessage()), $time);
         } catch (PHPUnit_Framework_InvalidCoversTargetException $cce) {
             $this->addFailure($test, new PHPUnit_Framework_InvalidCoversTargetError($cce->getMessage()), $time);
         } catch (PHP_CodeCoverage_Exception $cce) {
             $error = true;
             if (!isset($e)) {
                 $e = $cce;
             }
         }
     }
     if ($errorHandlerSet === true) {
         restore_error_handler();
     }
     if ($error === true) {
         $this->addError($test, $e, $time);
     } elseif ($failure === true) {
         $this->addFailure($test, $e, $time);
     } elseif ($this->beStrictAboutTestsThatDoNotTestAnything && $test->getNumAssertions() == 0) {
         $this->addFailure($test, new PHPUnit_Framework_RiskyTestError('This test did not perform any assertions'), $time);
     } elseif ($this->beStrictAboutOutputDuringTests && $test->hasOutput()) {
         $this->addFailure($test, new PHPUnit_Framework_OutputError(sprintf('This test printed output: %s', $test->getActualOutput())), $time);
     } elseif ($this->beStrictAboutTodoAnnotatedTests && $test instanceof PHPUnit_Framework_TestCase) {
         $annotations = $test->getAnnotations();
         if (isset($annotations['method']['todo'])) {
             $this->addFailure($test, new PHPUnit_Framework_RiskyTestError('Test method is annotated with @todo'), $time);
         }
     }
     $this->endTest($test, $time);
 }
Пример #19
0
<?php

require_once 'PHP/CodeCoverage/Autoload.php';
$coverage = new PHP_CodeCoverage();
$filter = $coverage->filter();
$filter->addFileToBlacklist(__FILE__);
$filter->addFileToBlacklist(dirname(__FILE__) . '/auto_append.php');
$coverage->start($_SERVER['SCRIPT_FILENAME']);
 protected function getCodeCoverage()
 {
     $coverage = new PHP_CodeCoverage();
     $filter = $coverage->filter();
     $filter->addFileToBlacklist(Director::baseFolder() . '/mysite/local.conf.php');
     $filter->addDirectoryToBlacklist(Director::baseFolder() . '/mysite/scripts');
     $modules = $this->moduleDirectories();
     foreach (TestRunner::config()->coverage_filter_dirs as $dir) {
         if ($dir[0] == '*') {
             $dir = substr($dir, 1);
             foreach ($modules as $module) {
                 $filter->addDirectoryToBlacklist(BASE_PATH . "/{$module}/{$dir}");
             }
         } else {
             $filter->addDirectoryToBlacklist(BASE_PATH . '/' . $dir);
         }
     }
     // whitelist for specific modules
     foreach ($this->moduleList as $directory) {
         $filter->addFileToBlacklist($directory . '/_config.php');
         $filter->addDirectoryToWhitelist($directory . '/code');
         $filter->addDirectoryToWhitelist($directory . '/src');
     }
     $filter->addFileToBlacklist(__FILE__, 'PHPUNIT');
     return $coverage;
 }
Пример #21
0
}
$cli = eZCLI::instance();
$script = eZScript::instance(array('description' => "eZ Publish Test Runner\n\n" . "sets up an eZ Publish testing environment" . "\n", 'use-session' => false, 'use-modules' => true, 'use-extensions' => true));
// Override INI override folder from settings/override to
// tests/settings to not read local override settings
$ini = eZINI::instance();
$ini->setOverrideDirs(array(array('tests/settings', true)), 'override');
$ini->loadCache();
// Be sure to have clean content language data
eZContentLanguage::expireCache();
$script->startup();
// $options = $script->getOptions();
$script->initialize();
// Avoids Fatal error: eZ Publish did not finish its request if die() is used.
eZExecution::setCleanExit();
$version = PHPUnit_Runner_Version::id();
if (version_compare($version, '3.5.0') == -1 && $version !== '@package_version@') {
    die("PHPUnit 3.5.0 (or later) is required to run this test suite.\n");
}
require_once 'PHP/CodeCoverage.php';
$codeCoverage = new PHP_CodeCoverage();
$codeCoverage->filter()->addFileToBlacklist(__FILE__, 'PHPUNIT');
//require_once 'bootstrap.php';
try {
    $runner = ezpTestRunner::instance();
    $runner->run($_SERVER['argv']);
} catch (Exception $e) {
    $cli->error($e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine());
    $cli->error($e->getTraceAsString());
}
$script->shutdown();
Пример #22
0
 /**
  * @return \PHP_CodeCoverage
  */
 public function coverage()
 {
     $coverage = new \PHP_CodeCoverage();
     $coverage->setData($this->data);
     $coverage->setTests($this->tests);
     $filter = $coverage->filter();
     $filter->setBlacklistedFiles($this->blackList);
     $filter->setWhitelistedFiles($this->whiteList);
     return $coverage;
 }
Пример #23
0
 /**
  * @param string           $filename
  * @param PHP_CodeCoverage $coverage
  */
 protected function handleConfiguration($filename, \PHP_CodeCoverage $coverage)
 {
     $filter = $coverage->filter();
     $configuration = \PHPUnit_Util_Configuration::getInstance($filename);
     $filterConfiguration = $configuration->getFilterConfiguration();
     $coverage->setAddUncoveredFilesFromWhitelist($filterConfiguration['whitelist']['addUncoveredFilesFromWhitelist']);
     $coverage->setProcessUncoveredFilesFromWhitelist($filterConfiguration['whitelist']['processUncoveredFilesFromWhitelist']);
     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);
     }
     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);
     }
 }
Пример #24
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['cacheTokens']) && !isset($arguments['cacheTokens'])) {
             $arguments['cacheTokens'] = $phpunitConfiguration['cacheTokens'];
         }
         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['strict']) && !isset($arguments['strict'])) {
             $arguments['strict'] = $phpunitConfiguration['strict'];
         }
         if (isset($phpunitConfiguration['verbose']) && !isset($arguments['verbose'])) {
             $arguments['verbose'] = $phpunitConfiguration['verbose'];
         }
         if (isset($phpunitConfiguration['forceCoversAnnotation']) && !isset($arguments['forceCoversAnnotation'])) {
             $arguments['forceCoversAnnotation'] = $phpunitConfiguration['forceCoversAnnotation'];
         }
         if (isset($phpunitConfiguration['mapTestClassNameToCoveredClassName']) && !isset($arguments['mapTestClassNameToCoveredClassName'])) {
             $arguments['mapTestClassNameToCoveredClassName'] = $phpunitConfiguration['mapTestClassNameToCoveredClassName'];
         }
         $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['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 = $this->codeCoverage->filter();
         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')) {
             $this->codeCoverage->setProcessUncoveredFilesFromWhitelist($filterConfiguration['whitelist']['addUncoveredFilesFromWhitelist']);
             if (isset($arguments['forceCoversAnnotation'])) {
                 $this->codeCoverage->setForceCoversAnnotation($arguments['forceCoversAnnotation']);
             }
             if (isset($arguments['mapTestClassNameToCoveredClassName'])) {
                 $this->codeCoverage->setMapTestClassNameToCoveredClassName($arguments['mapTestClassNameToCoveredClassName']);
             }
             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['cacheTokens'] = isset($arguments['cacheTokens']) ? $arguments['cacheTokens'] : TRUE;
     $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['repeat'] = isset($arguments['repeat']) ? $arguments['repeat'] : FALSE;
     $arguments['reportCharset'] = isset($arguments['reportCharset']) ? $arguments['reportCharset'] : 'UTF-8';
     $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['stopOnError'] = isset($arguments['stopOnError']) ? $arguments['stopOnError'] : FALSE;
     $arguments['stopOnFailure'] = isset($arguments['stopOnFailure']) ? $arguments['stopOnFailure'] : FALSE;
     $arguments['stopOnIncomplete'] = isset($arguments['stopOnIncomplete']) ? $arguments['stopOnIncomplete'] : FALSE;
     $arguments['stopOnSkipped'] = isset($arguments['stopOnSkipped']) ? $arguments['stopOnSkipped'] : FALSE;
     $arguments['strict'] = isset($arguments['strict']) ? $arguments['strict'] : FALSE;
     $arguments['verbose'] = isset($arguments['verbose']) ? $arguments['verbose'] : FALSE;
     if ($arguments['filter'] !== FALSE && preg_match('/^[a-zA-Z0-9_]/', $arguments['filter'])) {
         // Escape delimiters in regular expression. Do NOT use preg_quote,
         // to keep magic characters.
         $arguments['filter'] = '/' . str_replace('/', '\\/', $arguments['filter']) . '/';
     }
 }