Ejemplo n.º 1
0
 /**
  * Test merge for code coverage library 4 version
  *
  * @requires function \SebastianBergmann\CodeCoverage\CodeCoverage::merge
  */
 public function testSimpleMerge()
 {
     $firstFile = PARATEST_ROOT . '/src/ParaTest/Logging/LogInterpreter.php';
     $secondFile = PARATEST_ROOT . '/src/ParaTest/Logging/MetaProvider.php';
     $filter = new Filter();
     $filter->addFilesToWhitelist([$firstFile, $secondFile]);
     $coverage1 = new CodeCoverage(null, $filter);
     $coverage1->append(array($firstFile => array(35 => 1), $secondFile => array(34 => 1)), 'Test1');
     $coverage2 = new CodeCoverage(null, $filter);
     $coverage2->append(array($firstFile => array(35 => 1, 36 => 1)), 'Test2');
     $merger = new CoverageMerger();
     $this->call($merger, 'addCoverage', $coverage1);
     $this->call($merger, 'addCoverage', $coverage2);
     /** @var CodeCoverage $coverage */
     $coverage = $this->getObjectValue($merger, 'coverage');
     $this->assertInstanceOf('\\SebastianBergmann\\CodeCoverage\\CodeCoverage', $coverage);
     $data = $coverage->getData();
     $this->assertCount(2, $data[$firstFile][35]);
     $this->assertEquals('Test1', $data[$firstFile][35][0]);
     $this->assertEquals('Test2', $data[$firstFile][35][1]);
     $this->assertCount(1, $data[$firstFile][36]);
     $this->assertEquals('Test2', $data[$firstFile][36][0]);
     $this->assertCount(1, $data[$secondFile][34]);
     $this->assertEquals('Test1', $data[$secondFile][34][0]);
 }
Ejemplo n.º 2
0
 /**
  * If we are processing uncovered files from whitelist,
  * we can initialize the data before we start to speed up the tests
  */
 protected function initializeData()
 {
     $this->isInitialized = true;
     if ($this->processUncoveredFilesFromWhitelist) {
         $this->shouldCheckForDeadAndUnused = false;
         $this->driver->start(true);
         foreach ($this->filter->getWhitelist() as $file) {
             if ($this->filter->isFile($file)) {
                 include_once $file;
             }
         }
         $data = [];
         $coverage = $this->driver->stop();
         foreach ($coverage as $file => $fileCoverage) {
             if ($this->filter->isFiltered($file)) {
                 continue;
             }
             foreach (array_keys($fileCoverage) as $key) {
                 if ($fileCoverage[$key] == Driver::LINE_EXECUTED) {
                     $fileCoverage[$key] = Driver::LINE_NOT_EXECUTED;
                 }
             }
             $data[$file] = $fileCoverage;
         }
         $this->append($data, 'UNCOVERED_FILES_FROM_WHITELIST');
     }
 }
Ejemplo n.º 3
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'] : [];
     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['beStrictAboutChangesToGlobalState']) && !isset($arguments['beStrictAboutChangesToGlobalState'])) {
             $arguments['beStrictAboutChangesToGlobalState'] = $phpunitConfiguration['beStrictAboutChangesToGlobalState'];
         }
         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['stopOnError']) && !isset($arguments['stopOnError'])) {
             $arguments['stopOnError'] = $phpunitConfiguration['stopOnError'];
         }
         if (isset($phpunitConfiguration['stopOnFailure']) && !isset($arguments['stopOnFailure'])) {
             $arguments['stopOnFailure'] = $phpunitConfiguration['stopOnFailure'];
         }
         if (isset($phpunitConfiguration['stopOnWarning']) && !isset($arguments['stopOnWarning'])) {
             $arguments['stopOnWarning'] = $phpunitConfiguration['stopOnWarning'];
         }
         if (isset($phpunitConfiguration['stopOnIncomplete']) && !isset($arguments['stopOnIncomplete'])) {
             $arguments['stopOnIncomplete'] = $phpunitConfiguration['stopOnIncomplete'];
         }
         if (isset($phpunitConfiguration['stopOnRisky']) && !isset($arguments['stopOnRisky'])) {
             $arguments['stopOnRisky'] = $phpunitConfiguration['stopOnRisky'];
         }
         if (isset($phpunitConfiguration['stopOnSkipped']) && !isset($arguments['stopOnSkipped'])) {
             $arguments['stopOnSkipped'] = $phpunitConfiguration['stopOnSkipped'];
         }
         if (isset($phpunitConfiguration['failOnWarning']) && !isset($arguments['failOnWarning'])) {
             $arguments['failOnWarning'] = $phpunitConfiguration['failOnWarning'];
         }
         if (isset($phpunitConfiguration['failOnRisky']) && !isset($arguments['failOnRisky'])) {
             $arguments['failOnRisky'] = $phpunitConfiguration['failOnRisky'];
         }
         if (isset($phpunitConfiguration['timeoutForSmallTests']) && !isset($arguments['timeoutForSmallTests'])) {
             $arguments['timeoutForSmallTests'] = $phpunitConfiguration['timeoutForSmallTests'];
         }
         if (isset($phpunitConfiguration['timeoutForMediumTests']) && !isset($arguments['timeoutForMediumTests'])) {
             $arguments['timeoutForMediumTests'] = $phpunitConfiguration['timeoutForMediumTests'];
         }
         if (isset($phpunitConfiguration['timeoutForLargeTests']) && !isset($arguments['timeoutForLargeTests'])) {
             $arguments['timeoutForLargeTests'] = $phpunitConfiguration['timeoutForLargeTests'];
         }
         if (isset($phpunitConfiguration['reportUselessTests']) && !isset($arguments['reportUselessTests'])) {
             $arguments['reportUselessTests'] = $phpunitConfiguration['reportUselessTests'];
         }
         if (isset($phpunitConfiguration['strictCoverage']) && !isset($arguments['strictCoverage'])) {
             $arguments['strictCoverage'] = $phpunitConfiguration['strictCoverage'];
         }
         if (isset($phpunitConfiguration['disallowTestOutput']) && !isset($arguments['disallowTestOutput'])) {
             $arguments['disallowTestOutput'] = $phpunitConfiguration['disallowTestOutput'];
         }
         if (isset($phpunitConfiguration['enforceTimeLimit']) && !isset($arguments['enforceTimeLimit'])) {
             $arguments['enforceTimeLimit'] = $phpunitConfiguration['enforceTimeLimit'];
         }
         if (isset($phpunitConfiguration['disallowTodoAnnotatedTests']) && !isset($arguments['disallowTodoAnnotatedTests'])) {
             $arguments['disallowTodoAnnotatedTests'] = $phpunitConfiguration['disallowTodoAnnotatedTests'];
         }
         if (isset($phpunitConfiguration['beStrictAboutResourceUsageDuringSmallTests']) && !isset($arguments['beStrictAboutResourceUsageDuringSmallTests'])) {
             $arguments['beStrictAboutResourceUsageDuringSmallTests'] = $phpunitConfiguration['beStrictAboutResourceUsageDuringSmallTests'];
         }
         if (isset($phpunitConfiguration['verbose']) && !isset($arguments['verbose'])) {
             $arguments['verbose'] = $phpunitConfiguration['verbose'];
         }
         if (isset($phpunitConfiguration['reverseDefectList']) && !isset($arguments['reverseList'])) {
             $arguments['reverseList'] = $phpunitConfiguration['reverseDefectList'];
         }
         if (isset($phpunitConfiguration['forceCoversAnnotation']) && !isset($arguments['forceCoversAnnotation'])) {
             $arguments['forceCoversAnnotation'] = $phpunitConfiguration['forceCoversAnnotation'];
         }
         if (isset($phpunitConfiguration['disableCodeCoverageIgnore']) && !isset($arguments['disableCodeCoverageIgnore'])) {
             $arguments['disableCodeCoverageIgnore'] = $phpunitConfiguration['disableCodeCoverageIgnore'];
         }
         if (isset($phpunitConfiguration['registerMockObjectsFromTestArgumentsRecursively']) && !isset($arguments['registerMockObjectsFromTestArgumentsRecursively'])) {
             $arguments['registerMockObjectsFromTestArgumentsRecursively'] = $phpunitConfiguration['registerMockObjectsFromTestArgumentsRecursively'];
         }
         $groupCliArgs = [];
         if (!empty($arguments['groups'])) {
             $groupCliArgs = $arguments['groups'];
         }
         $groupConfiguration = $arguments['configuration']->getGroupConfiguration();
         if (!empty($groupConfiguration['include']) && !isset($arguments['groups'])) {
             $arguments['groups'] = $groupConfiguration['include'];
         }
         if (!empty($groupConfiguration['exclude']) && !isset($arguments['excludeGroups'])) {
             $arguments['excludeGroups'] = array_diff($groupConfiguration['exclude'], $groupCliArgs);
         }
         foreach ($arguments['configuration']->getListenerConfiguration() as $listener) {
             if (!class_exists($listener['class'], false) && $listener['file'] !== '') {
                 require_once $listener['file'];
             }
             if (!class_exists($listener['class'])) {
                 throw new PHPUnit_Framework_Exception(sprintf('Class "%s" does not exist', $listener['class']));
             }
             $listenerClass = new ReflectionClass($listener['class']);
             if (!$listenerClass->implementsInterface(PHPUnit_Framework_TestListener::class)) {
                 throw new PHPUnit_Framework_Exception(sprintf('Class "%s" does not implement the PHPUnit_Framework_TestListener interface', $listener['class']));
             }
             if (count($listener['arguments']) == 0) {
                 $listener = new $listener['class']();
             } else {
                 $listener = $listenerClass->newInstanceArgs($listener['arguments']);
             }
             $arguments['listeners'][] = $listener;
         }
         $loggingConfiguration = $arguments['configuration']->getLoggingConfiguration();
         if (isset($loggingConfiguration['coverage-clover']) && !isset($arguments['coverageClover'])) {
             $arguments['coverageClover'] = $loggingConfiguration['coverage-clover'];
         }
         if (isset($loggingConfiguration['coverage-crap4j']) && !isset($arguments['coverageCrap4J'])) {
             $arguments['coverageCrap4J'] = $loggingConfiguration['coverage-crap4j'];
             if (isset($loggingConfiguration['crap4jThreshold']) && !isset($arguments['crap4jThreshold'])) {
                 $arguments['crap4jThreshold'] = $loggingConfiguration['crap4jThreshold'];
             }
         }
         if (isset($loggingConfiguration['coverage-html']) && !isset($arguments['coverageHtml'])) {
             if (isset($loggingConfiguration['lowUpperBound']) && !isset($arguments['reportLowUpperBound'])) {
                 $arguments['reportLowUpperBound'] = $loggingConfiguration['lowUpperBound'];
             }
             if (isset($loggingConfiguration['highLowerBound']) && !isset($arguments['reportHighLowerBound'])) {
                 $arguments['reportHighLowerBound'] = $loggingConfiguration['highLowerBound'];
             }
             $arguments['coverageHtml'] = $loggingConfiguration['coverage-html'];
         }
         if (isset($loggingConfiguration['coverage-php']) && !isset($arguments['coveragePHP'])) {
             $arguments['coveragePHP'] = $loggingConfiguration['coverage-php'];
         }
         if (isset($loggingConfiguration['coverage-text']) && !isset($arguments['coverageText'])) {
             $arguments['coverageText'] = $loggingConfiguration['coverage-text'];
             if (isset($loggingConfiguration['coverageTextShowUncoveredFiles'])) {
                 $arguments['coverageTextShowUncoveredFiles'] = $loggingConfiguration['coverageTextShowUncoveredFiles'];
             } else {
                 $arguments['coverageTextShowUncoveredFiles'] = false;
             }
             if (isset($loggingConfiguration['coverageTextShowOnlySummary'])) {
                 $arguments['coverageTextShowOnlySummary'] = $loggingConfiguration['coverageTextShowOnlySummary'];
             } else {
                 $arguments['coverageTextShowOnlySummary'] = false;
             }
         }
         if (isset($loggingConfiguration['coverage-xml']) && !isset($arguments['coverageXml'])) {
             $arguments['coverageXml'] = $loggingConfiguration['coverage-xml'];
         }
         if (isset($loggingConfiguration['plain'])) {
             $arguments['listeners'][] = new PHPUnit_TextUI_ResultPrinter($loggingConfiguration['plain'], true);
         }
         if (isset($loggingConfiguration['teamcity']) && !isset($arguments['teamcityLogfile'])) {
             $arguments['teamcityLogfile'] = $loggingConfiguration['teamcity'];
         }
         if (isset($loggingConfiguration['junit']) && !isset($arguments['junitLogfile'])) {
             $arguments['junitLogfile'] = $loggingConfiguration['junit'];
         }
         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($loggingConfiguration['testdox-xml']) && !isset($arguments['testdoxXMLFile'])) {
             $arguments['testdoxXMLFile'] = $loggingConfiguration['testdox-xml'];
         }
         if ((isset($arguments['coverageClover']) || isset($arguments['coverageCrap4J']) || isset($arguments['coverageHtml']) || isset($arguments['coveragePHP']) || isset($arguments['coverageText']) || isset($arguments['coverageXml'])) && $this->runtime->canCollectCodeCoverage()) {
             $filterConfiguration = $arguments['configuration']->getFilterConfiguration();
             $arguments['addUncoveredFilesFromWhitelist'] = $filterConfiguration['whitelist']['addUncoveredFilesFromWhitelist'];
             $arguments['processUncoveredFilesFromWhitelist'] = $filterConfiguration['whitelist']['processUncoveredFilesFromWhitelist'];
             foreach ($filterConfiguration['whitelist']['include']['directory'] as $dir) {
                 $this->codeCoverageFilter->addDirectoryToWhitelist($dir['path'], $dir['suffix'], $dir['prefix']);
             }
             foreach ($filterConfiguration['whitelist']['include']['file'] as $file) {
                 $this->codeCoverageFilter->addFileToWhitelist($file);
             }
             foreach ($filterConfiguration['whitelist']['exclude']['directory'] as $dir) {
                 $this->codeCoverageFilter->removeDirectoryFromWhitelist($dir['path'], $dir['suffix'], $dir['prefix']);
             }
             foreach ($filterConfiguration['whitelist']['exclude']['file'] as $file) {
                 $this->codeCoverageFilter->removeFileFromWhitelist($file);
             }
         }
     }
     $arguments['addUncoveredFilesFromWhitelist'] = isset($arguments['addUncoveredFilesFromWhitelist']) ? $arguments['addUncoveredFilesFromWhitelist'] : true;
     $arguments['processUncoveredFilesFromWhitelist'] = isset($arguments['processUncoveredFilesFromWhitelist']) ? $arguments['processUncoveredFilesFromWhitelist'] : false;
     $arguments['backupGlobals'] = isset($arguments['backupGlobals']) ? $arguments['backupGlobals'] : null;
     $arguments['backupStaticAttributes'] = isset($arguments['backupStaticAttributes']) ? $arguments['backupStaticAttributes'] : null;
     $arguments['beStrictAboutChangesToGlobalState'] = isset($arguments['beStrictAboutChangesToGlobalState']) ? $arguments['beStrictAboutChangesToGlobalState'] : null;
     $arguments['cacheTokens'] = isset($arguments['cacheTokens']) ? $arguments['cacheTokens'] : false;
     $arguments['columns'] = isset($arguments['columns']) ? $arguments['columns'] : 80;
     $arguments['colors'] = isset($arguments['colors']) ? $arguments['colors'] : PHPUnit_TextUI_ResultPrinter::COLOR_DEFAULT;
     $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'] : [];
     $arguments['groups'] = isset($arguments['groups']) ? $arguments['groups'] : [];
     $arguments['processIsolation'] = isset($arguments['processIsolation']) ? $arguments['processIsolation'] : false;
     $arguments['repeat'] = isset($arguments['repeat']) ? $arguments['repeat'] : false;
     $arguments['reportHighLowerBound'] = isset($arguments['reportHighLowerBound']) ? $arguments['reportHighLowerBound'] : 90;
     $arguments['reportLowUpperBound'] = isset($arguments['reportLowUpperBound']) ? $arguments['reportLowUpperBound'] : 50;
     $arguments['crap4jThreshold'] = isset($arguments['crap4jThreshold']) ? $arguments['crap4jThreshold'] : 30;
     $arguments['stopOnError'] = isset($arguments['stopOnError']) ? $arguments['stopOnError'] : false;
     $arguments['stopOnFailure'] = isset($arguments['stopOnFailure']) ? $arguments['stopOnFailure'] : false;
     $arguments['stopOnWarning'] = isset($arguments['stopOnWarning']) ? $arguments['stopOnWarning'] : false;
     $arguments['stopOnIncomplete'] = isset($arguments['stopOnIncomplete']) ? $arguments['stopOnIncomplete'] : false;
     $arguments['stopOnRisky'] = isset($arguments['stopOnRisky']) ? $arguments['stopOnRisky'] : false;
     $arguments['stopOnSkipped'] = isset($arguments['stopOnSkipped']) ? $arguments['stopOnSkipped'] : false;
     $arguments['failOnWarning'] = isset($arguments['failOnWarning']) ? $arguments['failOnWarning'] : false;
     $arguments['failOnRisky'] = isset($arguments['failOnRisky']) ? $arguments['failOnRisky'] : false;
     $arguments['timeoutForSmallTests'] = isset($arguments['timeoutForSmallTests']) ? $arguments['timeoutForSmallTests'] : 1;
     $arguments['timeoutForMediumTests'] = isset($arguments['timeoutForMediumTests']) ? $arguments['timeoutForMediumTests'] : 10;
     $arguments['timeoutForLargeTests'] = isset($arguments['timeoutForLargeTests']) ? $arguments['timeoutForLargeTests'] : 60;
     $arguments['reportUselessTests'] = isset($arguments['reportUselessTests']) ? $arguments['reportUselessTests'] : true;
     $arguments['strictCoverage'] = isset($arguments['strictCoverage']) ? $arguments['strictCoverage'] : false;
     $arguments['disallowTestOutput'] = isset($arguments['disallowTestOutput']) ? $arguments['disallowTestOutput'] : false;
     $arguments['enforceTimeLimit'] = isset($arguments['enforceTimeLimit']) ? $arguments['enforceTimeLimit'] : false;
     $arguments['disallowTodoAnnotatedTests'] = isset($arguments['disallowTodoAnnotatedTests']) ? $arguments['disallowTodoAnnotatedTests'] : false;
     $arguments['beStrictAboutResourceUsageDuringSmallTests'] = isset($arguments['beStrictAboutResourceUsageDuringSmallTests']) ? $arguments['beStrictAboutResourceUsageDuringSmallTests'] : false;
     $arguments['reverseList'] = isset($arguments['reverseList']) ? $arguments['reverseList'] : false;
     $arguments['registerMockObjectsFromTestArgumentsRecursively'] = isset($arguments['registerMockObjectsFromTestArgumentsRecursively']) ? $arguments['registerMockObjectsFromTestArgumentsRecursively'] : false;
     $arguments['verbose'] = isset($arguments['verbose']) ? $arguments['verbose'] : false;
     $arguments['testdoxExcludeGroups'] = isset($arguments['testdoxExcludeGroups']) ? $arguments['testdoxExcludeGroups'] : [];
     $arguments['testdoxGroups'] = isset($arguments['testdoxGroups']) ? $arguments['testdoxGroups'] : [];
 }
Ejemplo n.º 4
0
 /**
  * @BeforeSuite
  */
 public static function setup()
 {
     $filter = new Filter();
     $filter->addDirectoryToWhitelist(__DIR__ . '/../../src');
     self::$coverage = new CodeCoverage(null, $filter);
 }
Ejemplo n.º 5
0
 protected function getCoverageForClassWithAnonymousFunction()
 {
     $filter = new Filter();
     $filter->addFileToWhitelist(TEST_FILES_PATH . 'source_with_class_and_anonymous_function.php');
     $coverage = new CodeCoverage($this->setUpXdebugStubForClassWithAnonymousFunction(), $filter);
     $coverage->start('ClassWithAnonymousFunction', true);
     $coverage->stop();
     return $coverage;
 }