/** * Stop collecting at the end of a request * * @param \Symfony\Component\HttpKernel\Event\PostResponseEvent $event */ public function onKernelTerminate(PostResponseEvent $event) { if (!$this->driver || !$this->repository->isEnabled()) { return; } $coverage = $this->driver->stop(); $this->repository->addCoverage($coverage); }
/** * 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'); }
/** * Stop collection of code coverage information. * * @param boolean $append * * @return array * @throws PHP_CodeCoverage_Exception */ public function stop($append = true) { if (!is_bool($append)) { throw PHP_CodeCoverage_Util_InvalidArgumentHelper::factory(1, 'boolean'); } $data = $this->driver->stop(); $this->append($data, null, $append); $this->currentId = null; return $data; }
/** * Stop collection of code coverage information. * * @param bool $append * @param mixed $linesToBeCovered * @param array $linesToBeUsed * @return array * @throws PHP_CodeCoverage_Exception */ public function stop($append = true, $linesToBeCovered = array(), array $linesToBeUsed = array()) { if (!is_bool($append)) { throw PHP_CodeCoverage_Util_InvalidArgumentHelper::factory(1, 'boolean'); } if (!is_array($linesToBeCovered) && $linesToBeCovered !== false) { throw PHP_CodeCoverage_Util_InvalidArgumentHelper::factory(2, 'array or false'); } $data = $this->driver->stop(); $this->append($data, null, $append, $linesToBeCovered, $linesToBeUsed); $this->currentId = null; return $data; }
/** * 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'); }
/** * @param string $uncoveredFile * @param array $data * @param array $uncoveredFiles */ private function processUncoveredFileFromWhitelist($uncoveredFile, array &$data, array $uncoveredFiles) { $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; } } }
/** * 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'); }