/** * Test case for the execution chain bug 14. * * @return void */ public function testAnalyzerExecutionChain() { $packages = self::parseCodeResourceForTest(); self::assertEquals(1, $packages->count()); self::assertEquals(1, $packages->current()->getFunctions()->count()); $analyzer = new PHP_Depend_Metrics_Coupling_Analyzer(); $analyzer->analyze($packages); $project = $analyzer->getProjectMetrics(); self::assertEquals(3, $project['calls']); }
/** * Aggregates the required metrics from the registered analyzers. * * @return array(string => mixed) * @throws RuntimeException If one of the required analyzers isn't set. */ private function collectMetrics() { if ($this->coupling === null) { throw new RuntimeException('Missing Coupling analyzer.'); } if ($this->cyclomaticComplexity === null) { throw new RuntimeException('Missing Cyclomatic Complexity analyzer.'); } if ($this->inheritance === null) { throw new RuntimeException('Missing Inheritance analyzer.'); } if ($this->nodeCount === null) { throw new RuntimeException('Missing Node Count analyzer.'); } if ($this->nodeLoc === null) { throw new RuntimeException('Missing Node LOC analyzer.'); } $coupling = $this->coupling->getProjectMetrics(); $cyclomatic = $this->cyclomaticComplexity->getProjectMetrics(); $inheritance = $this->inheritance->getProjectMetrics(); $nodeCount = $this->nodeCount->getProjectMetrics(); $nodeLoc = $this->nodeLoc->getProjectMetrics(); return array('cyclo' => $cyclomatic['ccn2'], 'loc' => $nodeLoc['eloc'], 'nom' => $nodeCount['nom'] + $nodeCount['nof'], 'noc' => $nodeCount['noc'], 'nop' => $nodeCount['nop'], 'ahh' => round($inheritance['ahh'], 3), 'andc' => round($inheritance['andc'], 3), 'fanout' => $coupling['fanout'], 'calls' => $coupling['calls']); }
/** * Test case for the execution chain bug 14. * * http://bugs.xplib.de/index.php?do=details&task_id=14&project=3 * * @return void * @covers PHP_Depend_Metrics_Coupling_Analyzer * @group pdepend * @group pdepend::metrics * @group pdepend::metrics::coupling * @group unittest */ public function testAnalyzerExecutionChainBug14() { $source = dirname(__FILE__) . '/../../_code/bugs/014.php'; $packages = self::parseSource($source); $this->assertEquals(1, $packages->count()); $this->assertEquals(1, $packages->current()->getFunctions()->count()); $analyzer = new PHP_Depend_Metrics_Coupling_Analyzer(); $analyzer->analyze($packages); $project = $analyzer->getProjectMetrics(); $this->assertArrayHasKey('calls', $project); $this->assertEquals(3, $project['calls']); }
/** * Tests that the analyzer calculates the expected result. * * @return void */ public function testAnalyzerDetectsDifferentMethodCalls() { $packages = self::parseCodeResourceForTest(); $analyzer = new PHP_Depend_Metrics_Coupling_Analyzer(); $analyzer->analyze($packages); $project = $analyzer->getProjectMetrics(); self::assertEquals(2, $project['calls']); }
/** * Tests that the analyzer calculates the expected result. * * @return void */ public function testAnalyzerDetectsObjectAllocation() { $packages = self::parseSource('bugs/089/' . __FUNCTION__ . '.php'); $analyzer = new PHP_Depend_Metrics_Coupling_Analyzer(); $analyzer->analyze($packages); $project = $analyzer->getProjectMetrics(); $this->assertSame(0, $project['calls']); }
/** * Tests that the analyzer calculates the expected result. * * @return void * @covers stdClass * @group pdepend * @group pdepend::bugs * @group regressiontest */ public function testAnalyzerDetectsObjectAllocation() { $packages = self::parseTestCaseSource(__METHOD__); $analyzer = new PHP_Depend_Metrics_Coupling_Analyzer(); $analyzer->analyze($packages); $project = $analyzer->getProjectMetrics(); self::assertEquals(0, $project['calls']); }
/** * Parses the source code for the currently calling test method and returns * the calculated project metrics. * * @param string $testCase Optional name of the calling test case. * * @return array(string=>mixed) * @since 0.10.2 */ private function _calculateProjectMetrics($testCase = null) { $testCase = $testCase ? $testCase : self::getCallingTestMethod(); $analyzer = new PHP_Depend_Metrics_Coupling_Analyzer(); $analyzer->analyze(self::parseTestCaseSource($testCase)); return $analyzer->getProjectMetrics(); }