Beispiel #1
0
 protected function doRun()
 {
     $data = array();
     $srcDirectory = new atoum\fs\path($this->srcDirectory);
     foreach (new iterators\recursives\atoum\source($this->srcDirectory) as $file) {
         $file = new atoum\fs\path($file);
         $data[(string) $file->relativizeFrom($srcDirectory)] = file_get_contents($file);
     }
     $bootstrapFile = new atoum\fs\path($this->bootstrapFile);
     $bootstrapFile = $bootstrapFile->relativizeFrom($srcDirectory);
     $bootstrap = '<?php $directory = sys_get_temp_dir() . \'/\' . basename(__FILE__);';
     $bootstrap .= '$bootstrap = $directory . \'/' . $bootstrapFile . '\';';
     $bootstrap .= 'if (is_file($bootstrap) === false || filemtime(__FILE__) > filemtime($bootstrap))';
     $bootstrap .= '{';
     $bootstrap .= '$data = eval(substr(file_get_contents(__FILE__), __COMPILER_HALT_OFFSET__));';
     $bootstrap .= 'foreach ($data as $file => $contents)';
     $bootstrap .= '{';
     $bootstrap .= '$file = $directory . \'/\' . $file;';
     $bootstrap .= '@mkdir(dirname($file), 0777, true);';
     $bootstrap .= '@file_put_contents($file, $contents);';
     $bootstrap .= '}';
     $bootstrap .= '}';
     $bootstrap .= 'require $bootstrap;';
     $bootstrap .= '__halt_compiler();';
     if (file_put_contents($this->destinationFile, $bootstrap . 'return ' . var_export($data, true) . ';') === false) {
         throw new exceptions\runtime(sprintf($this->locale->_('Unable to write in file \'%s\''), $this->destinationFile));
     }
     return $this;
 }
Beispiel #2
0
 public function isSubPathOf(path $path)
 {
     $this->resolve();
     $resolvedPath = $path->getResolvedPath();
     return $this->components !== $resolvedPath->components && ($resolvedPath->isRoot() === true || strpos($this->components, $resolvedPath->components . '/') === 0);
 }
Beispiel #3
0
 /**
  * @param array $classData
  * @param int   $relevantLines
  * @param int   $coveredLines
  * @param int   $totalLines
  * @param int   $coverage
  */
 protected function buildClassPage($classData, $relevantLines, $coveredLines, $totalLines, $coverage)
 {
     // get template
     $template = $this->templateParser->parseFile($this->templatesDirectory . DIRECTORY_SEPARATOR . 'class.tpl');
     // build common
     $this->buildCommonTemplate($template, array('totalLines' => $totalLines, 'relevantLines' => $relevantLines, 'coveredLines' => $coveredLines, 'coverage' => $coverage), $classData['coverage'], $classData['name']);
     $methodsTemplates = $template->methods;
     $methodTemplates = $methodsTemplates->method;
     $methodCoverageAvailableTemplates = $methodTemplates->methodCoverageAvailable;
     $methodCoverageUnavailableTemplates = $methodTemplates->methodCoverageUnavailable;
     $sourceFileTemplates = $template->sourceFile;
     $templates = array('lineTemplates' => $sourceFileTemplates->line, 'coveredLineTemplates' => $sourceFileTemplates->coveredLine, 'notCoveredLineTemplates' => $sourceFileTemplates->notCoveredLine);
     $className = $classData['className'];
     $template->className = $className;
     $methods = $this->coverage->getCoverageForClass($className);
     $reflectedMethods = array();
     $reflectionClassMethods = $this->getReflectionClass($className)->getMethods();
     foreach (array_filter($reflectionClassMethods, function ($reflectedMethod) use($className) {
         return $reflectedMethod->isAbstract() === false && $reflectedMethod->getDeclaringClass()->getName() === $className;
     }) as $reflectedMethod) {
         $reflectedMethods[$reflectedMethod->getName()] = $reflectedMethod;
     }
     if (sizeof($reflectedMethods) > 0) {
         foreach (array_intersect(array_keys($reflectedMethods), array_keys($methods)) as $methodName) {
             $methodCoverageValue = $this->coverage->getValueForMethod($className, $methodName);
             if ($methodCoverageValue === null) {
                 $methodCoverageUnavailableTemplates->build(array('methodName' => $methodName));
             } else {
                 $methodCoverageAvailableTemplates->build(array('methodName' => $methodName, 'methodCoverageValue' => round($methodCoverageValue * 100, 2), 'methodCoverageRounded' => ceil($methodCoverageValue * 100)));
             }
             $methodTemplates->build();
             $methodCoverageAvailableTemplates->resetData();
             $methodCoverageUnavailableTemplates->resetData();
         }
         $methodsTemplates->build();
         $methodTemplates->resetData();
     }
     $srcFile = $this->adapter->fopen($this->sourceDirectory->getRealPath()->__toString() . DIRECTORY_SEPARATOR . $classData['name'], 'r');
     if ($srcFile !== false) {
         $methodLines = array();
         foreach ($reflectedMethods as $reflectedMethodName => $reflectedMethod) {
             $methodLines[$reflectedMethod->getStartLine()] = $reflectedMethodName;
         }
         for ($currentMethod = null, $lineNumber = 1, $line = $this->adapter->fgets($srcFile); $line !== false; $lineNumber++, $line = $this->adapter->fgets($srcFile)) {
             if (isset($methodLines[$lineNumber]) === true) {
                 $currentMethod = $methodLines[$lineNumber];
             }
             switch (true) {
                 case isset($methods[$currentMethod]) === false || (isset($methods[$currentMethod][$lineNumber]) === false || $methods[$currentMethod][$lineNumber] == -2):
                     $lineTemplateName = 'lineTemplates';
                     break;
                 case isset($methods[$currentMethod]) === true && isset($methods[$currentMethod][$lineNumber]) === true && $methods[$currentMethod][$lineNumber] == -1:
                     $lineTemplateName = 'notCoveredLineTemplates';
                     break;
                 default:
                     $lineTemplateName = 'coveredLineTemplates';
             }
             $templates[$lineTemplateName]->lineNumber = $lineNumber;
             $templates[$lineTemplateName]->code = htmlentities($line, ENT_QUOTES, 'UTF-8');
             if (isset($methodLines[$lineNumber]) === true) {
                 foreach ($templates[$lineTemplateName]->anchor as $anchorTemplate) {
                     $anchorTemplate->resetData();
                     $anchorTemplate->method = $currentMethod;
                     $anchorTemplate->build();
                 }
             }
             $templates[$lineTemplateName]->addToParent()->resetData();
         }
         $this->adapter->fclose($srcFile);
     }
     $file = $this->destinationDirectory . DIRECTORY_SEPARATOR . str_replace('\\', '/', $className) . self::HTML_EXTENSION_FILE;
     $directory = $this->adapter->dirname($file);
     if ($this->adapter->is_dir($directory) === false) {
         $this->adapter->mkdir($directory, 0777, true);
     }
     $this->adapter->file_put_contents($file, (string) $template->build());
 }
Beispiel #4
0
 public function testPutContents()
 {
     $this->if($path = new testedClass('/a/b', '/'))->and($adapter = new atoum\test\adapter())->and($adapter->mkdir = true)->and($adapter->file_put_contents = true)->and($path->setAdapter($adapter))->then->object($path->putContents($data = uniqid()))->isEqualTo($path)->adapter($adapter)->call('mkdir')->withArguments('/a', true)->once()->call('file_put_contents')->withArguments((string) $path, $data)->once()->if($adapter->file_put_contents = false)->then->exception(function () use($path, &$data) {
         $path->putContents($data = uniqid());
     })->isInstanceOf('mageekguy\\atoum\\fs\\path\\exception')->hasMessage('Unable to put data \'' . $data . '\' in file \'' . $path . '\'');
 }
Beispiel #5
0
 protected function makeSourceElement(score\coverage $coverage)
 {
     $sources = array();
     foreach ($coverage->getClasses() as $class => $file) {
         $path = new atoum\fs\path($file);
         $source = $this->adapter->file_get_contents((string) $path->resolve());
         $sources[] = array('name' => ltrim((string) $path->relativizeFrom($this->sourceDir), '.' . DIRECTORY_SEPARATOR), 'source' => $source, 'coverage' => $this->makeCoverageElement($coverage->getCoverageForClass($class)));
     }
     return $sources;
 }