/** * Test merge for code coverage library 3 version * * @requires function \PHP_CodeCoverage::merge */ public function testSimpleMergeLegacy() { $firstFile = PARATEST_ROOT . '/src/ParaTest/Logging/LogInterpreter.php'; $secondFile = PARATEST_ROOT . '/src/ParaTest/Logging/MetaProvider.php'; $filter = new \PHP_CodeCoverage_Filter(); $filter->addFilesToWhitelist([$firstFile, $secondFile]); $coverage1 = new \PHP_CodeCoverage(null, $filter); $coverage1->append(array($firstFile => array(35 => 1), $secondFile => array(34 => 1)), 'Test1'); $coverage2 = new \PHP_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 \PHP_CodeCoverage $coverage */ $coverage = $this->getObjectValue($merger, 'coverage'); $this->assertInstanceOf('\\PHP_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]); }
/** * CodeCoverage constructor */ public function __construct() { $filter = new \PHP_CodeCoverage_Filter(); $filter->addDirectoryToWhitelist(__DIR__ . '/../app'); $filter->addDirectoryToWhitelist(__DIR__ . '/../src'); $this->coverage = new \PHP_CodeCoverage(null, $filter); $this->writer = new \PHP_CodeCoverage_Report_PHP(); }
/** @BeforeSuite */ public static function setup() { if (!self::$coverage) { $filter = new \PHP_CodeCoverage_Filter(); $filter->addDirectoryToBlacklist(__DIR__ . '/../../../vendor'); $filter->addDirectoryToWhitelist(__DIR__ . '/../../../Bundle'); self::$coverage = new \PHP_CodeCoverage(null, $filter); } }
/** * JBZooPHPUnit_Coverage constructor. * @SuppressWarnings(PHPMD.Superglobals) */ public function __construct() { if (Env::hasXdebug() && isset($_REQUEST['jbzoo-phpunit'])) { $cmsType = $_REQUEST['jbzoo-phpunit-type']; $testName = $_REQUEST['jbzoo-phpunit-test']; $this->_covRoot = realpath(__DIR__ . '/../..'); $this->_covDir = realpath($this->_covRoot . '/src'); $this->_covHash = implode('_', [md5(serialize($_REQUEST)), mt_rand(0, 100000000)]); $this->_covResult = realpath($this->_covRoot . '/build/coverage_cov') . '/' . $cmsType . '-' . $testName . '.cov'; $covFilter = new PHP_CodeCoverage_Filter(); $covFilter->addDirectoryToWhitelist($this->_covDir); $this->_coverage = new PHP_CodeCoverage(null, $covFilter); } }
/** * CovCatcher constructor. * @param string $testName * @param array $options * @throws Exception */ public function __construct($testName = null, array $options = array()) { if (!class_exists('\\JBZoo\\Data\\Data')) { throw new Exception('jbzoo/data required for CovCatcher'); } if (!class_exists('\\JBZoo\\Utils\\Env')) { throw new Exception('jbzoo/utils required for CovCatcher'); } $this->_initConfig($options); $this->_hash = $this->_getPrefix($testName) . '_' . md5(serialize($this->_config->getArrayCopy()) . '|' . $testName); if (Env::hasXdebug()) { $covFilter = new \PHP_CodeCoverage_Filter(); $covFilter->addDirectoryToWhitelist($this->_config->get('src')); $this->_coverage = new \PHP_CodeCoverage(null, $covFilter); } }
/** * Add Mockery files to PHPUnit's blacklist so they don't showup on coverage reports */ public function startTestSuite(\PHPUnit_Framework_TestSuite $suite) { if (class_exists('\\PHP_CodeCoverage_Filter') && method_exists('\\PHP_CodeCoverage_Filter', 'getInstance')) { \PHP_CodeCoverage_Filter::getInstance()->addDirectoryToBlacklist(__DIR__ . '/../../../Mockery/', '.php', '', 'PHPUNIT'); \PHP_CodeCoverage_Filter::getInstance()->addFileToBlacklist(__DIR__ . '/../../../Mockery.php', 'PHPUNIT'); } }
/** * Processes whitelisted files that are not covered. */ protected function processUncoveredFilesFromWhitelist() { $data = array(); $uncoveredFiles = array_diff($this->filter->getWhitelist(), array_keys($this->coveredFiles)); $newVariables = array(); $newVariableNames = array(); $oldVariableNames = array(); $uncoveredFile = NULL; $variableName = NULL; foreach ($uncoveredFiles as $uncoveredFile) { if ($this->promoteGlobals) { $oldVariableNames = array_keys(get_defined_vars()); } $this->driver->start(); include_once $uncoveredFile; $coverage = $this->driver->stop(); if ($this->promoteGlobals) { $newVariables = get_defined_vars(); $newVariableNames = array_diff(array_keys($newVariables), $oldVariableNames); foreach ($newVariableNames as $variableName) { if ($variableName != 'oldVariableNames') { $GLOBALS[$variableName] = $newVariables[$variableName]; } } } foreach ($coverage as $file => $fileCoverage) { if (!isset($data[$file])) { $data[$file] = $fileCoverage; } } } $this->append($data, 'UNCOVERED_FILES_FROM_WHITELIST'); }
/** * Processes whitelisted files that are not covered. */ private function addUncoveredFilesFromWhitelist() { $data = array(); $uncoveredFiles = array_diff( $this->filter->getWhitelist(), array_keys($this->data) ); foreach ($uncoveredFiles as $uncoveredFile) { if (!file_exists($uncoveredFile)) { continue; } if ($this->processUncoveredFilesFromWhitelist) { $this->processUncoveredFileFromWhitelist( $uncoveredFile, $data, $uncoveredFiles ); } else { $data[$uncoveredFile] = array(); $lines = count(file($uncoveredFile)); for ($i = 1; $i <= $lines; $i++) { $data[$uncoveredFile][$i] = -1; } } } $this->append($data, 'UNCOVERED_FILES_FROM_WHITELIST'); }
/** * Create the test result and splice on our code coverage reports. * * @return PHPUnit_Framework_TestResult */ protected function createTestResult() { $result = new PHPUnit_Framework_TestResult(); $FixtureInjector = new FixtureInjector($this->_getFixtureManager(array())); $result->addListener($FixtureInjector); if (!empty($this->_params['codeCoverage'])) { if (method_exists($result, 'collectCodeCoverageInformation')) { $result->collectCodeCoverageInformation(true); } if (method_exists($result, 'setCodeCoverage')) { $Filter = new PHP_CodeCoverage_Filter(); $Filter->addFileToBlacklist('systemlib.php'); $result->setCodeCoverage(new PHP_CodeCoverage(null, $Filter)); } } return $result; }
/** * Get the code coverage filter instance we will use for tests. * When running PHPUnit 3.5, this will return the singleton instance. * When running PHPUnit 3.6, this will return the instance we hold internally; * this same instance will be passed to PHPUnit in AgaviTesting::dispatch(). * * @return PHP_CodeCoverage_Filter The code coverage filter for our tests. * * @author David Zülke <*****@*****.**> * @since 1.0.7 * @deprecated 1.1.0 Use AgaviPhpUnitCli */ public static function getCodeCoverageFilter() { if (self::$codeCoverageFilter === null) { // PHP_CodeCoverage doesn't expose any version info, we'll have to check if there is a static getInstance method self::$codeCoverageFilter = method_exists('PHP_CodeCoverage_Filter', 'getInstance') ? PHP_CodeCoverage_Filter::getInstance() : new PHP_CodeCoverage_Filter(); } return self::$codeCoverageFilter; }
/** * Initialise the wrapper class. */ public function init() { require_once 'PHP/CodeCoverage.php'; require_once 'PHP/CodeCoverage/Report/HTML.php'; require_once 'PHPUnit/Autoload.php'; require_once 'PHP/CodeCoverage/Filter.php'; PHP_CodeCoverage_Filter::getInstance()->addFileToBlacklist(__FILE__, 'PHPUNIT'); }
/** * Set up the test suite. * * @return void * @access protected */ protected function setUp() { // Update the code coverage blacklist -- we don't want to analyze all the // test code or any external PEAR libraries that we include: PHP_CodeCoverage_Filter::getInstance()->addDirectoryToBlacklist('/usr/share/php'); PHP_CodeCoverage_Filter::getInstance()->addDirectoryToBlacklist('/usr/local/lib'); PHP_CodeCoverage_Filter::getInstance()->addDirectoryToBlacklist(dirname(__FILE__)); // Clear out Smarty files to ensure testing begins with a clean slate: $this->_smartyCleanup(); }
function phpunit_autoload($class) { if (strpos($class, 'PHPUnit_') === 0) { $file = str_replace('_', '/', $class) . '.php'; $file = PHPUnit_Util_Filesystem::fileExistsInIncludePath($file); if ($file) { require_once $file; PHP_CodeCoverage_Filter::getInstance()->addFileToBlacklist($file, 'PHPUNIT'); } } }
protected function setCodeCoverageIgnores() { $codeCoverageFilter = PHP_CodeCoverage_Filter::getInstance(); $codeCoverageFilter->addDirectoryToBlacklist(dirname(__FILE__)); foreach($this->codeCoverageIgnoreDirectoryList as $oneDirectory) { $codeCoverageFilter->addDirectoryToBlacklist($oneDirectory); } $codeCoverageFilter->addFilesToBlackList($this->codeCoverageIgnoreFileList); }
/** * Set white / black lists */ public function setWhiteAndBlacklists() { if ($this->isPhpunitVersionGreaterOrEquals("3.6.0")) { $filter = new PHP_CodeCoverage_Filter(); $filter->addDirectoryToBlacklist(PATH_TO_TEST_DIR); $filter->addDirectoryToBlacklist(PATH_TO_TINE_LIBRARY); $filter->addDirectoryToBlacklist(PATH_TO_REAL_DIR . '/Setup'); $filter->addDirectoryToBlacklist(PATH_TO_REAL_DIR . '/Zend'); } else { if ($this->isPhpunitVersionGreaterOrEquals("3.5.0")) { PHP_CodeCoverage_Filter::getInstance()->addDirectoryToBlacklist(PATH_TO_TEST_DIR); PHP_CodeCoverage_Filter::getInstance()->addDirectoryToBlacklist(PATH_TO_TINE_LIBRARY); PHP_CodeCoverage_Filter::getInstance()->addDirectoryToBlacklist(PATH_TO_REAL_DIR . '/Setup'); PHP_CodeCoverage_Filter::getInstance()->addDirectoryToBlacklist(PATH_TO_REAL_DIR . '/Zend'); } else { PHPUnit_Util_Filter::addDirectoryToFilter(PATH_TO_TEST_DIR); PHPUnit_Util_Filter::addDirectoryToFilter(PATH_TO_TINE_LIBRARY); PHPUnit_Util_Filter::addDirectoryToFilter(PATH_TO_REAL_DIR . '/Setup'); PHPUnit_Util_Filter::addDirectoryToFilter(PATH_TO_REAL_DIR . '/Zend'); } } }
/** * Processes whitelisted files that are not covered. */ protected function processUncoveredFilesFromWhitelist() { $data = array(); $uncoveredFiles = array_diff($this->filter->getWhitelist(), array_keys($this->data)); foreach ($uncoveredFiles as $uncoveredFile) { if (!file_exists($uncoveredFile)) { continue; } if ($this->cacheTokens) { $tokens = PHP_Token_Stream_CachingFactory::get($uncoveredFile); } else { $tokens = new PHP_Token_Stream($uncoveredFile); } $classes = $tokens->getClasses(); $interfaces = $tokens->getInterfaces(); $functions = $tokens->getFunctions(); unset($tokens); foreach (array_keys($classes) as $class) { if (class_exists($class, FALSE)) { continue 2; } } unset($classes); foreach (array_keys($interfaces) as $interface) { if (interface_exists($interface, FALSE)) { continue 2; } } unset($interfaces); foreach (array_keys($functions) as $function) { if (function_exists($function)) { continue 2; } } unset($functions); $this->driver->start(); include_once $uncoveredFile; $coverage = $this->driver->stop(); foreach ($coverage as $file => $fileCoverage) { if (!isset($data[$file]) && in_array($file, $uncoveredFiles)) { foreach (array_keys($fileCoverage) as $key) { if ($fileCoverage[$key] == 1) { $fileCoverage[$key] = -1; } } $data[$file] = $fileCoverage; } } } $this->append($data, 'UNCOVERED_FILES_FROM_WHITELIST'); }
public function testSimpleMerge() { $firstFile = PARATEST_ROOT . '/src/ParaTest/Logging/LogInterpreter.php'; $secondFile = PARATEST_ROOT . '/src/ParaTest/Logging/MetaProvider.php'; $filter = new \PHP_CodeCoverage_Filter(); $filter->addFilesToWhitelist([$firstFile, $secondFile]); $coverage1 = new \PHP_CodeCoverage(null, $filter); $coverage1->append(array($firstFile => array(35 => 1), $secondFile => array(34 => 1)), 'Test1'); $coverage2 = new \PHP_CodeCoverage(null, $filter); $coverage2->append(array($firstFile => array(35 => 1, 36 => 1)), 'Test2'); $merger = new CoverageMerger(); $merger->addCoverage($coverage1); $merger->addCoverage($coverage2); $coverage = $merger->getCoverage(); $data = $coverage->getData(); $this->assertEquals(2, count($data[$firstFile][35])); $this->assertEquals('Test1', $data[$firstFile][35][0]); $this->assertEquals('Test2', $data[$firstFile][35][1]); $this->assertEquals(1, count($data[$firstFile][36])); $this->assertEquals('Test2', $data[$firstFile][36][0]); $this->assertEquals(1, count($data[$secondFile][34])); $this->assertEquals('Test1', $data[$secondFile][34][0]); }
/** * Performs blacklist and whitelist as well as @codeCoverageIgnore* filtering. * * @param array $data */ private function filter(array &$data) { foreach (array_keys($data) as $filename) { if ($this->filter->isFiltered($filename)) { unset($data[$filename]); continue; } foreach ($this->parser->getLinesToBeIgnored($filename) as $line) { unset($data[$filename][$line]); } if (empty($data[$filename])) { unset($data[$filename]); } } }
/** * Initializes the Spec library * * @static * @param bool $autoload Unless it's false it will register a custom autoloader * @return bool */ public static function init($autoload = true) { static $alreadyInitialized = false; if ($alreadyInitialized) { return false; } // Register auto loader if ($autoload) { self::autoload(); } // Register stream wrapper for spec files $scheme = self::SCHEME; if (!in_array($scheme, stream_get_wrappers())) { // Get loaded extensions $extensions = array_merge(get_loaded_extensions(), get_loaded_extensions(true)); // Check if the Suhosin patch is loaded if (in_array('suhosin', $extensions)) { $list = ini_get('suhosin.executor.include.whitelist'); $list = explode(',', $list); $list = array_filter(array_map('trim', $list)); if (!in_array($scheme, $list)) { throw new \RuntimeException("The Suhosin patch has been detected but the custom '{$scheme}' scheme was not found as allowed. " . "Please review your php.ini settings to include '{$scheme}' in 'suhosin.executor.include.whitelist'."); } } stream_wrapper_register($scheme, __NAMESPACE__ . '\\Spec\\StreamWrapper'); } // Black list Spec files for PHPUnit if (class_exists('\\PHP_CodeCoverage_Filter', false)) { $filter = \PHP_CodeCoverage_Filter::getInstance(); $filter->addFileToBlacklist(__FILE__, 'PHPUNIT'); $filter->addDirectoryToBlacklist(__DIR__ . DIRECTORY_SEPARATOR . 'Spec', '.php', '', 'PHPUNIT', FALSE); // Also add Hamcrest matcher library from the include path $paths = explode(PATH_SEPARATOR, get_include_path()); foreach ($paths as $path) { if (is_file($path . DIRECTORY_SEPARATOR . 'Hamcrest/MatcherAssert.php')) { $filter->addDirectoryToBlacklist($path . DIRECTORY_SEPARATOR . 'Hamcrest', '.php', '', 'PHPUNIT', FALSE); break; } } } // include standard matchers and keywords include_once __DIR__ . '/Spec/keywords.php'; include_once __DIR__ . '/Spec/matchers.php'; // Setup suite stack self::$suites = new \SplStack(); return true; }
protected function createRunner() { if ($this->version36) { $filter = new PHP_CodeCoverage_Filter(); } else { $filter = PHP_CodeCoverage_Filter::getInstance(); } $filter->addFileToBlacklist(__FILE__, 'PHPUNIT'); $filter->addFileToBlacklist(__DIR__ . '/JelixTestSuite.class.php', 'PHPUNIT'); $filter->addFileToBlacklist(__DIR__ . '/junittestcase.class.php', 'PHPUNIT'); $filter->addFileToBlacklist(__DIR__ . '/junittestcasedb.class.php', 'PHPUNIT'); $filter->addFileToBlacklist(dirname(__DIR__) . '/phpunit.inc.php', 'PHPUNIT'); if ($this->version36) { return new PHPUnit_TextUI_TestRunner($this->arguments['loader'], $filter); } else { return new PHPUnit_TextUI_TestRunner($this->arguments['loader']); } }
/** * Merges the data from another instance of PHP_CodeCoverage. * * @param PHP_CodeCoverage $that */ public function merge(PHP_CodeCoverage $that) { 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()); }
/** * Processes whitelisted files that are not covered. */ protected function processUncoveredFilesFromWhitelist() { $data = array(); $includedFiles = array_flip(get_included_files()); $uncoveredFiles = array_diff($this->filter->getWhitelist(), $this->coveredFiles); foreach ($uncoveredFiles as $uncoveredFile) { if (isset($includedFiles[$uncoveredFile])) { foreach (array_keys($this->data) as $test) { if (isset($this->data[$test]['raw'][$uncoveredFile])) { $coverage = $this->data[$test]['raw'][$uncoveredFile]; foreach (array_keys($coverage) as $key) { if ($coverage[$key] == 1) { $coverage[$key] = -1; } } $data[$uncoveredFile] = $coverage; break; } } } else { $this->driver->start(); include_once $uncoveredFile; $coverage = $this->driver->stop(); foreach ($coverage as $file => $fileCoverage) { if (!isset($data[$file]) && in_array($file, $uncoveredFiles)) { foreach (array_keys($fileCoverage) as $key) { if ($fileCoverage[$key] == 1) { $fileCoverage[$key] = -1; } } $data[$file] = $fileCoverage; $includedFiles[$file] = TRUE; } } } } $this->append($data, 'UNCOVERED_FILES_FROM_WHITELIST'); }
* 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. * * @category Testing * @package PHPUnit * @author Kore Nordmann <*****@*****.**> * @author Sebastian Bergmann <*****@*****.**> * @copyright 2002-2010 Sebastian Bergmann <*****@*****.**> * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @link http://www.phpunit.de/ * @since File available since Release 3.0.0 */ require_once 'PHPUnit/Util/Type.php'; PHP_CodeCoverage_Filter::getInstance()->addFileToBlacklist(__FILE__, 'PHPUNIT'); /** * Constraint that checks if one value is equal to another. * * Equality is checked with PHP's == operator, the operator is explained in * detail at {@url http://www.php.net/manual/en/types.comparisons.php}. * Two values are equal if they have the same value disregarding type. * * The expected value is passed in the constructor. * * @category Testing * @package PHPUnit * @author Kore Nordmann <*****@*****.**> * @author Sebastian Bergmann <*****@*****.**> * @copyright 2002-2010 Sebastian Bergmann <*****@*****.**> * @license http://www.opensource.org/licenses/bsd-license.php BSD License
/** * @return PHP_CodeCoverage_Filter */ private function getCodeCoverageFilter() { $filter = new PHP_CodeCoverage_Filter(); if (defined('__PHPUNIT_PHAR__')) { $filter->addFileToBlacklist(__PHPUNIT_PHAR__); } $blacklist = new PHPUnit_Util_Blacklist(); foreach ($blacklist->getBlacklistedDirectories() as $directory) { $filter->addDirectoryToBlacklist($directory); } return $filter; }
require 'vendor/phpunit/php-code-coverage/src/CodeCoverage/Report/HTML.php'; require 'vendor/phpunit/php-code-coverage/src/CodeCoverage/Report/Clover.php'; require 'vendor/phpunit/php-token-stream/src/Token/Stream.php'; require 'vendor/sebastian/version/src/Version.php'; require 'vendor/symfony/yaml/Yaml.php'; require 'vendor/phpunit/php-text-template/src/Template.php'; require 'vendor/phpunit/php-token-stream/src/Token.php'; require 'vendor/phpunit/php-code-coverage/src/CodeCoverage/Driver.php'; require 'vendor/phpunit/php-code-coverage/src/CodeCoverage/Driver/Xdebug.php'; require 'vendor/sebastian/environment/src/Runtime.php'; require 'vendor/phpunit/php-code-coverage/src/CodeCoverage.php'; require 'vendor/phpunit/php-file-iterator/src/Iterator.php'; require 'vendor/phpunit/php-file-iterator/src/Factory.php'; require 'vendor/phpunit/php-file-iterator/src/Facade.php'; require 'vendor/phpunit/php-code-coverage/src/CodeCoverage/Filter.php'; $filter = new PHP_CodeCoverage_Filter(); $filter->addFileToBlacklist('fmt.php'); $filter->addFileToBlacklist('fmt.src.php'); $filter->addFileToBlacklist('test.php'); $filter->addDirectoryToBlacklist('vendor'); $coverage = new PHP_CodeCoverage(null, $filter); } $testNumber = ''; if (isset($opt['testNumber'])) { if (is_numeric($opt['testNumber'])) { $testNumber = sprintf('%03d', (int) $opt['testNumber']); } else { $testNumber = sprintf('%s', $opt['testNumber']); } } $bogomips = null;
break; default: $finfo = finfo_open(); $mime = finfo_file($finfo, $file, FILEINFO_MIME); finfo_close($finfo); break; } $size = filesize($file); $time = filemtime($file); header('HTTP/1.1 200 OK'); header('Content-Type: ' . $mime); header('Content-Length: ' . $size); header('Etag: ' . md5("{$size}-{$time}")); header('Last-Modified: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', $time)); readfile($file); } else { header('HTTP/1.0 404 Not Found'); } exit(0); } require $config['phpunit'] . 'PHPUnit/Autoload.php'; $filter = PHP_CodeCoverage_Filter::getInstance(); $filter->addDirectoryToBlacklist(__DIR__, '.php', '', 'PHPUNIT', FALSE); $filter->addDirectoryToBlacklist(__DIR__ . '/templates', '.php', '', 'PHPUNIT', FALSE); $filter->addDirectoryToBlacklist($config['tpldir'], '.php', '', 'PHPUNIT', FALSE); $filter->addFileToBlacklist(__FILE__, 'PHPUNIT', FALSE); $filter->addFileToBlacklist($_SERVER['SCRIPT_FILENAME'], 'PHPUNIT', FALSE); require __DIR__ . '/PHPUnit_Html_Printer.php'; require __DIR__ . '/PHPUnit_Html_TestRunner.php'; PHPUnit_HTML_TestRunner::run($config); /* vim: set expandtab tabstop=4 shiftwidth=4: */
/** * Recursively whitelists an array of files * * @param array $files Array of files to whitelist */ protected static function set_whitelist($files) { if (self::$phpunit_v35) { $filter = PHP_CodeCoverage_Filter::getInstance(); } foreach ($files as $file) { if (is_array($file)) { self::set_whitelist($file); } else { if (!isset(Kohana_Tests::$cache[$file])) { $relative_path = substr($file, strrpos($file, 'classes' . DIRECTORY_SEPARATOR) + 8, -strlen(EXT)); $cascading_file = Kohana::find_file('classes', $relative_path); // The theory is that if this file is the highest one in the cascading filesystem // then it's safe to whitelist Kohana_Tests::$cache[$file] = $cascading_file === $file; } if (Kohana_Tests::$cache[$file]) { if (isset($filter)) { $filter->addFileToWhitelist($file); } else { PHPUnit_Util_Filter::addFileToWhitelist($file); } } } } }
$fileName = ''; $namespace = ''; if ($lastNsPos = strrpos($className, '\\')) { $namespace = substr($className, 0, $lastNsPos); $className = substr($className, $lastNsPos + 1); $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; } $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; require $fileName; }); } /** * Code coverage option */ if (defined('TESTS_GENERATE_REPORT') && TESTS_GENERATE_REPORT === true) { $codeCoverageFilter = new PHP_CodeCoverage_Filter(); $lastArg = end($_SERVER['argv']); if (is_dir($zfCoreTests . '/' . $lastArg)) { $codeCoverageFilter->addDirectoryToWhitelist($zfCoreLibrary . '/' . $lastArg); } elseif (is_file($zfCoreTests . '/' . $lastArg)) { $codeCoverageFilter->addDirectoryToWhitelist(dirname($zfCoreLibrary . '/' . $lastArg)); } else { $codeCoverageFilter->addDirectoryToWhitelist($zfCoreLibrary); } /* * Omit from code coverage reports the contents of the tests directory */ $codeCoverageFilter->addDirectoryToBlacklist($zfCoreTests, ''); $codeCoverageFilter->addDirectoryToBlacklist(PEAR_INSTALL_DIR, ''); $codeCoverageFilter->addDirectoryToBlacklist(PHP_LIBDIR, ''); unset($codeCoverageFilter);
*/ require_once 'File/Iterator/Autoload.php'; require_once 'PHP/CodeCoverage/Autoload.php'; // Set this to the directory that contains the code coverage files. // It defaults to getcwd(). If you have configured a different directory // in prepend.php, you need to configure the same directory here. $GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY'] = getcwd(); if (isset($_GET['PHPUNIT_SELENIUM_TEST_ID'])) { $facade = new File_Iterator_Facade(); $files = $facade->getFilesAsArray($GLOBALS['PHPUNIT_COVERAGE_DATA_DIRECTORY'], $_GET['PHPUNIT_SELENIUM_TEST_ID']); $coverage = array(); foreach ($files as $file) { $data = unserialize(file_get_contents($file)); unlink($file); unset($file); $filter = new PHP_CodeCoverage_Filter(); foreach ($data as $file => $lines) { if ($filter->isFile($file)) { if (!isset($coverage[$file])) { $coverage[$file] = array('md5' => md5_file($file), 'coverage' => $lines); } else { foreach ($lines as $line => $flag) { if (!isset($coverage[$file]['coverage'][$line]) || $flag > $coverage[$file]['coverage'][$line]) { $coverage[$file]['coverage'][$line] = $flag; } } } } } } print serialize($coverage);
/** * @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['deprecatedCheckForUnintentionallyCoveredCodeSettingUsed'])) { $arguments['deprecatedCheckForUnintentionallyCoveredCodeSettingUsed'] = true; } 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']; } $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'])) { 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-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['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['teamcity']) && !isset($arguments['teamcityLogfile'])) { $arguments['teamcityLogfile'] = $loggingConfiguration['teamcity']; } 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['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['logIncompleteSkipped'] = isset($arguments['logIncompleteSkipped']) ? $arguments['logIncompleteSkipped'] : false; $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'] : false; $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['verbose'] = isset($arguments['verbose']) ? $arguments['verbose'] : false; }