-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #464 from denniscoorn-paqt/fix/complexity-table-co…
…lumns Fixed issue with incorrect table header on the complexity report
- Loading branch information
Showing
8 changed files
with
101 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
namespace Test\Hal\Reporter\Html; | ||
|
||
use DOMNode; | ||
use Hal\Application\Config\Config; | ||
use Hal\Component\Output\TestOutput; | ||
use Hal\Metric\Group\Group; | ||
use Hal\Metric\Metrics; | ||
use Hal\Report\Html\Reporter; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\DomCrawler\Crawler; | ||
|
||
/** | ||
* @group reporter | ||
* @group html | ||
*/ | ||
class ComplexityReportRegressionTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider tableHeaderDataProvider | ||
*/ | ||
public function testComplexityHtmlReportContainsCorrectOrderOfTableColumns($junitEnabled, $expectedTableHeader) | ||
{ | ||
$config = new Config(); | ||
$output = new TestOutput(); | ||
$reporter = new Reporter($config, $output); | ||
|
||
// prepares data for report | ||
$groups = []; | ||
$groups[] = new Group('group', '.*'); | ||
$config->set('groups', $groups); | ||
|
||
if ($junitEnabled) { | ||
$config->set('junit', ['file' => '/tmp/junit.xml']); | ||
} | ||
|
||
// prepares destination | ||
$destination = implode(DIRECTORY_SEPARATOR, [ | ||
sys_get_temp_dir(), | ||
'phpmetrics-html' . uniqid('', true) | ||
]); | ||
|
||
$config->set('report-html', $destination); | ||
|
||
// generates report | ||
$metrics = new Metrics(); | ||
$reporter->generate($metrics); | ||
|
||
// ensure complexity report contains expected table header columns | ||
$content = file_get_contents(sprintf('%s/complexity.html', $destination)); | ||
$actualTableHeader = $this->getActualTableHeader($content); | ||
|
||
$this->assertEquals($expectedTableHeader, $actualTableHeader); | ||
} | ||
|
||
public function tableHeaderDataProvider() | ||
{ | ||
$defaultTableHeader = [ | ||
'Class', | ||
'WMC', | ||
'Class cycl.', | ||
'Max method cycl.', | ||
'Relative system complexity', | ||
'Relative data complexity', | ||
'Relative structural complexity', | ||
'Bugs', | ||
'Defects', | ||
]; | ||
|
||
$junitTableHeader = array_merge($defaultTableHeader, [ | ||
'Unit testsuites calling it' | ||
]); | ||
|
||
return [ | ||
'junit disabled' => [false, $defaultTableHeader], | ||
'junit enabled' => [true, $junitTableHeader], | ||
]; | ||
} | ||
|
||
private function getActualTableHeader($content) | ||
{ | ||
$tableHeaderColumnNodes = (new Crawler($content)) | ||
->filterXPath('.//table[contains(concat(" ",normalize-space(@class)," ")," js-sort-table ")]/thead/tr') | ||
->children(); | ||
|
||
return array_map(function (DomNode $node) { | ||
return $node->textContent; | ||
}, iterator_to_array($tableHeaderColumnNodes)); | ||
} | ||
} |