Exemple #1
0
 public function testICanGetBoundsFromCollection()
 {
     $collection = $this->getMockBuilder('\\Hal\\Component\\Result\\ResultCollection')->disableOriginalConstructor()->getMock();
     $collection->expects($this->any())->method('asArray')->will($this->returnValue(array(array('volume' => 0, 'length' => 100), array('volume' => 10, 'length' => 50))));
     $bounds = new Bounds();
     $result = $bounds->calculate($collection);
     $this->assertInstanceOf('\\Hal\\Component\\Bounds\\Result\\BoundsResult', $result);
     $this->assertEquals(0, $result->getMin('volume'));
     $this->assertEquals(5, $result->getAverage('volume'));
     $this->assertEquals(10, $result->getMax('volume'));
     $this->assertEquals(150, $result->getSum('length'));
 }
 /**
  * @inheritdoc
  */
 public function execute(ResultCollection $collection, ResultCollection $aggregatedResults)
 {
     $this->output->write(str_pad("\rGrouping results by package/directory. This will take few minutes...", 80, " "));
     // Aggregates results
     $groupedResults = $this->aggregator->aggregates($collection);
     // metrics tools
     $abstractness = new Abstractness();
     $bounds = new Bounds();
     $instability = new Instability();
     foreach ($groupedResults as $namespace => $results) {
         // we filter aggregates to conserve only direct results
         $childs = new ResultCollection();
         foreach ($results as $r) {
             if ($namespace === dirname($r->getName())) {
                 $childs->push($r);
             }
         }
         $resultAggregate = new ResultAggregate($namespace);
         $resultAggregate->setAbstractness($abstractness->calculate($results))->setInstability($instability->calculate($results))->setBounds($bounds->calculate($results))->setChilds($childs);
         $aggregatedResults->push($resultAggregate);
     }
 }