Skip to content

Commit

Permalink
Generate reports for testphase files
Browse files Browse the repository at this point in the history
  • Loading branch information
nohponex committed May 25, 2016
1 parent 5449ddd commit cb75214
Show file tree
Hide file tree
Showing 4 changed files with 236 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ localsettings.php
build/
/bin/*.symbolic.php
.idea/**
tests/report/*.html
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"squizlabs/php_codesniffer": "*",
"apigen/apigen": "^4.1",
"phpunit/phpunit": "5.*",
"satooshi/php-coveralls": "dev-master"
"satooshi/php-coveralls": "dev-master",
"league/commonmark": "^0.13.3"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down Expand Up @@ -53,7 +54,8 @@
"apigen generate -s ./src,./vendor/phramework/validate/src,./vendor/phramework/exceptions/src -d ./doc --template-theme bootstrap --todo --tree --deprecated --no-source-code --title \"testphase\"",
"start=\"file://\";end=\"doc/index.html\"; echo \"\nOpen $start$(pwd)/$end\" in browser..."
],
"run": "php ./bin/testphase -d ./tests/tests -b ./tests/tests/Bootstrap.php --show-globals --verbose"
"run": "php ./bin/testphase -d ./tests/tests -b ./tests/tests/Bootstrap.php --show-globals --verbose",
"report": "./tools/generate-report.php --dir ./tests/tests/ --out ./tests/report"
},
"bin": [
"bin/testphase"
Expand Down
Empty file added tests/report/.gitkeep
Empty file.
231 changes: 231 additions & 0 deletions tools/generate-report.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
#!/usr/bin/env php
<?php

require __DIR__ . '/../vendor/autoload.php';

use Phramework\Testphase\TestParser;
use Phramework\Util\File;
use GetOptionKit\OptionCollection;
use GetOptionKit\OptionParser;
use GetOptionKit\OptionPrinter\ConsoleOptionPrinter;

$specs = new OptionCollection;

$specs->add('d|dir:', 'Tests directory path')
->isa('String');

$specs->add('s|subdir?', 'Optional, subdirectory')
->isa('String')
->defaultValue('');

$specs->add('o|out:', 'Report output path')
->isa('String');

$specs->add('h|help', 'Show help')
->defaultValue(false);

$parser = new OptionParser($specs);

$arguments = $parser->parse($argv);

if ($arguments->help) {
echo 'Help:' . PHP_EOL;
$printer = new ConsoleOptionPrinter;
echo $printer->render($specs);

return 0;
}

if (empty($arguments->dir)) {
echo '--dir is required, use --help for help' . PHP_EOL;
return 2;
}

if (empty($arguments->out)) {
echo '--out is required, use --help for help' . PHP_EOL;
return 2;
}

$path = $arguments->dir;

$subDir = $arguments->subdir;

$testDir = str_replace('//', '/', $path . '/'. $subDir);

var_dump($testDir);

if (!file_exists($testDir)) {
throw new Exception('Testphase directory not found');
}

$testFiles = File::directoryToArray(
$testDir,
true,
false,
true,
'/^\.|\.\.$/',
['json'],
false
);


/**
* @var \Phramework\Testphase\TestParser[]
*/
$testParserCollection = [];

$report = str_replace(
'//',
'/',
sprintf(
'%s/report%s.html',
$arguments->out,
(
empty($subDir)
? ''
: '-' . $subDir
)
)
);

$f = fopen($report, 'w');

if ($f === false) {
throw new Exception('Unable to create report file');
}

fwrite(
$f,
sprintf(
<<<'TAG'
<!DOCTYPE html>
<html>
<head>
<title>testphase report%s</title>
<link href="https://maxcdn.bootstrapcdn.com/bootswatch/3.3.6/paper/bootstrap.min.css" rel="stylesheet">
</head>
<body>
TAG
,
(
empty($subDir)
? ''
: ' - ' . $subDir
)
)
);

fwrite($f, '<div class="table-responsive"><table class="table table-striped table-condensed"><tr>');

$headers = ['order', 'file', 'ignore', 'description', 'incomplete'];

array_map(
function ($h) use ($f) {
fwrite(
$f,
sprintf(
'<th>%s</th>',
$h
)
);
},
$headers
);


foreach ($testFiles as $filename) {
$testParser = new TestParser($filename);

$testParserCollection[] = $testParser;

}

uasort(
$testParserCollection,
[\Phramework\Testphase\Binary::class, 'sortTestParser']
);

$converter = new \League\CommonMark\CommonMarkConverter();

foreach ($testParserCollection as $t) {

$meta = $t->getMeta();

$class = '';

if ($meta->incomplete) {
$class = 'warning';
}
if ($meta->ignore) {
$class = 'danger';
}

fwrite(
$f,
sprintf(
'<tr class="%s">',
$class
)
);


fwrite(
$f,
sprintf(
'<td><code>%s</code></td>',
$meta->order
)
);
fwrite(
$f,
sprintf(
'<td><code>%s</code></td>',
str_replace($testDir, '', $t->getFilename())
)
);
fwrite(
$f,
sprintf(
'<td>%s</td>',
(
$meta->ignore
? 'yes'
: ''
)
)
);
fwrite(
$f,
sprintf(
'<td>%s</td>',
$converter->convertToHtml(
$meta->description
)
)
);
fwrite(
$f,
sprintf(
'<td>%s</td>',
(
$meta->incomplete == true
? 'yes'
: $converter->convertToHtml(
$meta->incomplete
)
)
)
);

fwrite(
$f,
'</tr>'
);
}

fwrite($f, '</table>');
fwrite($f, '</div></body></html>');

fclose($f);

echo 'Report saved ' . $report . PHP_EOL;

0 comments on commit cb75214

Please sign in to comment.