Exemple #1
0
 public function merge(score\coverage $coverage)
 {
     $paths = $coverage->getPaths();
     $branches = $coverage->getBranches();
     $classes = $coverage->getClasses();
     $methods = $coverage->getMethods();
     foreach ($methods as $class => $methods) {
         $reflectedClass = call_user_func($this->reflectionClassFactory, $class);
         if ($this->isExcluded($reflectedClass) === false) {
             if (isset($this->classes[$class]) === false) {
                 $this->classes[$class] = $classes[$class];
             }
             if (isset($paths[$class]) && isset($this->paths[$class]) === false) {
                 $this->paths[$class] = $paths[$class];
             }
             if (isset($branches[$class]) && isset($this->branches[$class]) === false) {
                 $this->branches[$class] = $branches[$class];
             }
             foreach ($methods as $method => $lines) {
                 if (isset($paths[$class]) === true) {
                     if (isset($this->paths[$class][$method]) === false) {
                         $this->paths[$class][$method] = $paths[$class][$method];
                     }
                     foreach ($paths[$class][$method] as $index => $path) {
                         if ($this->paths[$class][$method][$index]['hit'] < $path['hit']) {
                             $this->paths[$class][$method][$index]['hit'] = $path['hit'];
                         }
                     }
                 }
                 if (isset($branches[$class]) === true) {
                     if (isset($this->branches[$class][$method]) === false) {
                         $this->branches[$class][$method] = $branches[$class][$method];
                     }
                     foreach ($branches[$class][$method] as $index => $branch) {
                         if ($this->branches[$class][$method][$index]['hit'] < $branch['hit']) {
                             $this->branches[$class][$method][$index]['hit'] = $branch['hit'];
                         }
                         foreach ($branch['out'] as $outIndex => $outOp) {
                             if (isset($this->branches[$class][$method][$index]['out'][$outIndex]) === false) {
                                 $this->branches[$class][$method][$index]['out'][$outIndex] = $outOp;
                             }
                         }
                         foreach ($branch['out_hit'] as $outIndex => $hit) {
                             if (isset($this->branches[$class][$method][$index]['out_hit'][$outIndex]) === false) {
                                 $this->branches[$class][$method][$index]['out_hit'][$outIndex] = $hit;
                             } else {
                                 if ($this->branches[$class][$method][$index]['out_hit'][$outIndex] < $hit) {
                                     $this->branches[$class][$method][$index]['out_hit'][$outIndex] = $hit;
                                 }
                             }
                         }
                     }
                 }
                 if (isset($this->methods[$class][$method]) === true || $this->isExcluded($this->getDeclaringClass($reflectedClass->getMethod($method))) === false) {
                     foreach ($lines as $line => $call) {
                         if (isset($this->methods[$class][$method][$line]) === false || $this->methods[$class][$method][$line] < $call) {
                             $this->methods[$class][$method][$line] = $call;
                         }
                     }
                 }
             }
         }
     }
     return $this;
 }
Exemple #2
0
 public function testMerge()
 {
     $this->if($classController = new mock\controller())->and($classController->disableMethodChecking())->and($classController->__construct = function () {
     })->and($classController->getName = function () use(&$className) {
         return $className;
     })->and($classController->getFileName = function () use(&$classFile) {
         return $classFile;
     })->and($classController->getTraits = array())->and($classController->getStartLine = 1)->and($classController->getEndLine = 12)->and($class = new \mock\reflectionClass(uniqid(), $classController))->and($methodController = new mock\controller())->and($methodController->__construct = function () {
     })->and($methodController->getName = function () use(&$methodName) {
         return $methodName;
     })->and($methodController->isAbstract = false)->and($methodController->getFileName = function () use(&$classFile) {
         return $classFile;
     })->and($methodController->getDeclaringClass = function () use($class) {
         return $class;
     })->and($methodController->getStartLine = 6)->and($methodController->getEndLine = 8)->and($method = new \mock\reflectionMethod(uniqid(), uniqid(), $methodController))->and($classController->getMethod = function () use($method) {
         return $method;
     })->and($classController->getMethods = array($method))->and($classFile = uniqid())->and($className = uniqid())->and($methodName = uniqid())->and($xdebugData = array($classFile => array(5 => -2, 6 => -1, 7 => 1, 8 => -2, 9 => -2), uniqid() => array(5 => 2, 6 => 3, 7 => 4, 8 => 3, 9 => 2)))->and($coverage = new testedClass())->and($coverage->setReflectionClassFactory(function () use($class) {
         return $class;
     }))->then->object($coverage->merge($coverage))->isIdenticalTo($coverage)->array($coverage->getClasses())->isEmpty()->array($coverage->getMethods())->isEmpty()->if($otherCoverage = new testedClass())->then->object($coverage->merge($otherCoverage))->isIdenticalTo($coverage)->array($coverage->getClasses())->isEmpty()->array($coverage->getMethods())->isEmpty()->if($coverage->addXdebugDataForTest($this, $xdebugData))->then->object($coverage->merge($otherCoverage))->isIdenticalTo($coverage)->array($coverage->getClasses())->isEqualTo(array($className => $classFile))->array($coverage->getMethods())->isEqualTo(array($className => array($methodName => array(6 => -1, 7 => 1, 8 => -2))))->object($coverage->merge($coverage))->isIdenticalTo($coverage)->array($coverage->getClasses())->isEqualTo(array($className => $classFile))->array($coverage->getMethods())->isEqualTo(array($className => array($methodName => array(6 => -1, 7 => 1, 8 => -2))))->if($otherClassController = new mock\controller())->and($otherClassController->disableMethodChecking())->and($otherClassController->__construct = function () {
     })->and($otherClassController->getName = function () use(&$otherClassName) {
         return $otherClassName;
     })->and($otherClassController->getFileName = function () use(&$otherClassFile) {
         return $otherClassFile;
     })->and($otherClassController->getTraits = array())->and($otherClassController->getStartLine = 1)->and($otherClassController->getEndLine = 12)->and($otherClass = new \mock\reflectionClass($class, $otherClassController))->and($otherMethodController = new mock\controller())->and($otherMethodController->__construct = function () {
     })->and($otherMethodController->getName = function () use(&$otherMethodName) {
         return $otherMethodName;
     })->and($otherMethodController->isAbstract = false)->and($otherMethodController->getFileName = function () use(&$otherClassFile) {
         return $otherClassFile;
     })->and($otherMethodController->getDeclaringClass = function () use($otherClass) {
         return $otherClass;
     })->and($otherMethodController->getStartLine = 5)->and($otherMethodController->getEndLine = 9)->and($otherClassController->getMethods = array(new \mock\reflectionMethod(uniqid(), uniqid(), $otherMethodController)))->and($otherClassFile = uniqid())->and($otherClassName = uniqid())->and($otherMethodName = uniqid())->and($otherXdebugData = array($otherClassFile => array(1 => -2, 2 => -1, 3 => 1, 4 => 1, 5 => -1, 6 => 1, 7 => 1, 8 => -1, 9 => -2, 10 => 1), uniqid() => array(500 => 200, 600 => 300, 700 => 400, 800 => 300, 900 => 200)))->and($otherCoverage->setReflectionClassFactory(function () use($otherClass) {
         return $otherClass;
     }))->then->object($coverage->merge($otherCoverage->addXdebugDataForTest($this, $otherXdebugData)))->isIdenticalTo($coverage)->array($coverage->getClasses())->isEqualTo(array($className => $classFile, $otherClassName => $otherClassFile))->array($coverage->getMethods())->isEqualTo(array($className => array($methodName => array(6 => -1, 7 => 1, 8 => -2)), $otherClassName => array($otherMethodName => array(5 => -1, 6 => 1, 7 => 1, 8 => -1, 9 => -2))))->if($classController = new mock\controller())->and($classController->disableMethodChecking())->and($classController->__construct = function () {
     })->and($classController->getName = function () use(&$className) {
         return $className;
     })->and($classController->getFileName = function () use(&$classFile) {
         return $classFile;
     })->and($classController->getTraits = array())->and($classController->getStartLine = 1)->and($classController->getEndLine = 12)->and($class = new \mock\reflectionClass(uniqid(), $classController))->and($methodController = new mock\controller())->and($methodController->__construct = function () {
     })->and($methodController->getName = function () use(&$methodName) {
         return $methodName;
     })->and($methodController->isAbstract = false)->and($methodController->getFileName = function () use(&$classFile) {
         return $classFile;
     })->and($methodController->getDeclaringClass = function () use($class) {
         return $class;
     })->and($methodController->getStartLine = 6)->and($methodController->getEndLine = 8)->and($method = new \mock\reflectionMethod(uniqid(), uniqid(), $methodController))->and($classController->getMethod = function () use($method) {
         return $method;
     })->and($classController->getMethods = array($method))->and($classFile = uniqid())->and($className = uniqid())->and($methodName = uniqid())->and($xdebugData = array($classFile => array(5 => -2, 6 => -1, 7 => 1, 8 => -2, 9 => -2), uniqid() => array(5 => 2, 6 => 3, 7 => 4, 8 => 3, 9 => 2)))->and($coverage = new testedClass())->and($coverage->setReflectionClassFactory(function () use($class) {
         return $class;
     }))->and($coverage->excludeClass($className))->and($otherCoverage = new testedClass())->and($otherCoverage->setReflectionClassFactory(function () use($class) {
         return $class;
     }))->and($otherCoverage->addXdebugDataForTest($this, $xdebugData))->then->array($otherCoverage->getClasses())->isNotEmpty()->array($otherCoverage->getMethods())->isNotEmpty()->object($coverage->merge($otherCoverage))->isIdenticalTo($coverage)->array($coverage->getClasses())->isEmpty()->array($coverage->getMethods())->isEmpty();
 }
 public function merge(score\coverage $coverage)
 {
     $classes = $coverage->getClasses();
     $methods = $coverage->getMethods();
     foreach ($methods as $class => $methods) {
         $reflectedClass = call_user_func($this->reflectionClassFactory, $class);
         if ($this->isExcluded($reflectedClass) === false) {
             if (isset($this->classes[$class]) === false) {
                 $this->classes[$class] = $classes[$class];
             }
             foreach ($methods as $method => $lines) {
                 if (isset($this->methods[$class][$method]) === true || $this->isExcluded($this->getDeclaringClass($reflectedClass->getMethod($method))) === false) {
                     foreach ($lines as $line => $call) {
                         if (isset($this->methods[$class][$method][$line]) === false || $this->methods[$class][$method][$line] < $call) {
                             $this->methods[$class][$method][$line] = $call;
                         }
                     }
                 }
             }
         }
     }
     return $this;
 }