-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new file mapper
- Loading branch information
Showing
7 changed files
with
211 additions
and
158 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,17 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
$locations = [ | ||
__DIR__ . '/../vendor/autoload.php', | ||
__DIR__ . '/vendor/autoload.php', | ||
__DIR__ . '/../autoload.php' | ||
]; | ||
namespace exussum12\CoverageChecker; | ||
|
||
$found = false; | ||
include (__DIR__ . "/../functions.php"); | ||
|
||
foreach ($locations as $file) { | ||
if (file_exists($file)) { | ||
require_once($file); | ||
$found = true; | ||
break; | ||
} | ||
} | ||
setUp(); | ||
$minimumPercentCovered = getMinPercent(); | ||
|
||
if (!$found) { | ||
error_log( | ||
"Can't find the autoload file," . | ||
"please make sure 'composer install' has been run" | ||
); | ||
|
||
exit(1); | ||
} | ||
|
||
if (!isset($argv[1], $argv[2])) { | ||
error_log( | ||
"Missing arguments, please call with diff and check file" | ||
); | ||
exit(1); | ||
} | ||
|
||
if ($argv[1] == "-") { | ||
$argv[1] = "php://stdin"; | ||
} | ||
if ($argv[2] == "-") { | ||
$argv[2] = "php://stdin"; | ||
} | ||
|
||
$matcher = new exussum12\CoverageChecker\FileMatchers\EndsWith(); | ||
$diff = new exussum12\CoverageChecker\DiffFileLoader($argv[1]); | ||
$phpunit = new exussum12\CoverageChecker\PhpCsLoader($argv[2]); | ||
$coverageCheck = new exussum12\CoverageChecker\CoverageCheck($diff, $phpunit, $matcher); | ||
$matcher = new FileMatchers\EndsWith(); | ||
$diff = new DiffFileLoader($argv[1]); | ||
$phpunit = new PhpCsLoader($argv[2]); | ||
$coverageCheck = new CoverageCheck($diff, $phpunit, $matcher); | ||
|
||
$lines = $coverageCheck->getCoveredLines(); | ||
|
||
$uncoveredLines = count($lines['uncoveredLines'], COUNT_RECURSIVE); | ||
|
||
if (empty($uncoveredLines)) { | ||
exit(0); | ||
} | ||
|
||
print_r($lines['uncoveredLines']); | ||
exit(2); | ||
handleOutput($lines, $minimumPercentCovered); |
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 |
---|---|---|
@@ -1,56 +1,17 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
$locations = [ | ||
__DIR__ . '/../vendor/autoload.php', | ||
__DIR__ . '/vendor/autoload.php', | ||
__DIR__ . '/../autoload.php' | ||
]; | ||
namespace exussum12\CoverageChecker; | ||
|
||
$found = false; | ||
include (__DIR__ . "/../functions.php"); | ||
|
||
foreach ($locations as $file) { | ||
if (file_exists($file)) { | ||
require_once($file); | ||
$found = true; | ||
break; | ||
} | ||
} | ||
setUp(); | ||
$minimumPercentCovered = getMinPercent(); | ||
|
||
if (!$found) { | ||
error_log( | ||
"Can't find the autoload file," . | ||
"please make sure 'composer install' has been run" | ||
); | ||
|
||
exit(1); | ||
} | ||
|
||
if (!isset($argv[1], $argv[2])) { | ||
error_log( | ||
"Missing arguments, please call with diff and check file" | ||
); | ||
exit(1); | ||
} | ||
|
||
if ($argv[1] == "-") { | ||
$argv[1] = "php://stdin"; | ||
} | ||
if ($argv[2] == "-") { | ||
$argv[2] = "php://stdin"; | ||
} | ||
|
||
$matcher = new exussum12\CoverageChecker\FileMatchers\EndsWith(); | ||
$diff = new exussum12\CoverageChecker\DiffFileLoader($argv[1]); | ||
$phpunit = new exussum12\CoverageChecker\PhpMdLoader($argv[2]); | ||
$coverageCheck = new exussum12\CoverageChecker\CoverageCheck($diff, $phpunit, $matcher); | ||
$matcher = new FileMatchers\EndsWith(); | ||
$diff = new DiffFileLoader($argv[1]); | ||
$phpunit = new PhpMdLoader($argv[2]); | ||
$coverageCheck = new CoverageCheck($diff, $phpunit, $matcher); | ||
|
||
$lines = $coverageCheck->getCoveredLines(); | ||
|
||
$uncoveredLines = count($lines['uncoveredLines'], COUNT_RECURSIVE); | ||
|
||
if (empty($uncoveredLines)) { | ||
exit(0); | ||
} | ||
|
||
print_r($lines['uncoveredLines']); | ||
exit(2); | ||
handleOutput($lines, $minimumPercentCovered); |
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 |
---|---|---|
@@ -1,69 +1,17 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
$locations = [ | ||
__DIR__ . '/../vendor/autoload.php', | ||
__DIR__ . '/vendor/autoload.php', | ||
__DIR__ . '/../autoload.php' | ||
]; | ||
namespace exussum12\CoverageChecker; | ||
|
||
$found = false; | ||
require_once (__DIR__ . "/../functions.php"); | ||
|
||
foreach ($locations as $file) { | ||
if (file_exists($file)) { | ||
require_once($file); | ||
$found = true; | ||
break; | ||
} | ||
} | ||
setUp(); | ||
$minimumPercentCovered = getMinPercent(); | ||
|
||
if (!$found) { | ||
error_log( | ||
"Can't find the autoload file," . | ||
"please make sure 'composer install' has been run" | ||
); | ||
|
||
exit(1); | ||
} | ||
|
||
if (!isset($argv[1], $argv[2])) { | ||
error_log( | ||
"Missing arguments, please call with diff and check file" | ||
); | ||
exit(1); | ||
} | ||
|
||
if ($argv[1] == "-") { | ||
$argv[1] = "php://stdin"; | ||
} | ||
if ($argv[2] == "-") { | ||
$argv[2] = "php://stdin"; | ||
} | ||
|
||
$minimumPercentCovered = 100; | ||
if (isset($argv[3])) { | ||
$minimumPercentCovered = min($minimumPercentCovered, max(0, $argv[3])); | ||
} | ||
|
||
|
||
$matcher = new exussum12\CoverageChecker\FileMatchers\EndsWith(); | ||
$diff = new exussum12\CoverageChecker\DiffFileLoader($argv[1]); | ||
$phpunit = new exussum12\CoverageChecker\XMLReport($argv[2]); | ||
$coverageCheck = new exussum12\CoverageChecker\CoverageCheck($diff, $phpunit, $matcher); | ||
$matcher = new FileMatchers\EndsWith(); | ||
$diff = new DiffFileLoader($argv[1]); | ||
$phpunit = new XMLReport($argv[2]); | ||
$coverageCheck = new CoverageCheck($diff, $phpunit, $matcher); | ||
|
||
$lines = $coverageCheck->getCoveredLines(); | ||
|
||
$coveredLines = count($lines['coveredLines'], COUNT_RECURSIVE); | ||
$uncoveredLines = count($lines['uncoveredLines'], COUNT_RECURSIVE); | ||
|
||
if($coveredLines + $uncoveredLines == 0) { | ||
exit(0); | ||
} | ||
|
||
$percentCovered = 100 * ($coveredLines / ($coveredLines + $uncoveredLines)); | ||
if ($percentCovered >= $minimumPercentCovered) { | ||
exit(0); | ||
} | ||
|
||
echo "$percentCovered% Covered, Missed lines " . PHP_EOL; | ||
print_r($lines['uncoveredLines']); | ||
exit(2); | ||
handleOutput($lines, $minimumPercentCovered); |
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,87 @@ | ||
<?php | ||
namespace exussum12\CoverageChecker; | ||
|
||
function setUp() | ||
{ | ||
findAutoLoader(); | ||
checkCallIsCorrect(); | ||
adjustForStdIn(); | ||
} | ||
|
||
function findAutoLoader() | ||
{ | ||
$locations = [ | ||
__DIR__ . '/vendor/autoload.php', | ||
__DIR__ . '/autoload.php' | ||
]; | ||
|
||
$found = false; | ||
|
||
foreach ($locations as $file) { | ||
if (file_exists($file)) { | ||
require_once($file); | ||
$found = true; | ||
break; | ||
} | ||
} | ||
|
||
if (!$found) { | ||
error_log( | ||
"Can't find the autoload file," . | ||
"please make sure 'composer install' has been run" | ||
); | ||
|
||
exit(1); | ||
} | ||
} | ||
|
||
function checkCallIsCorrect() | ||
{ | ||
global $argv; | ||
if (!isset($argv[1], $argv[2])) { | ||
error_log( | ||
"Missing arguments, please call with diff and check file" | ||
); | ||
exit(1); | ||
} | ||
} | ||
|
||
function adjustForStdIn() | ||
{ | ||
global $argv; | ||
foreach ([1, 2] as $arg) { | ||
if ($argv[$arg] == "-") { | ||
$argv[$arg] = "php://stdin"; | ||
} | ||
} | ||
} | ||
|
||
function getMinPercent() | ||
{ | ||
global $argv; | ||
$minimumPercentCovered = 100; | ||
if (isset($argv[3])) { | ||
$minimumPercentCovered = min($minimumPercentCovered, max(0, $argv[3])); | ||
return $minimumPercentCovered; | ||
} | ||
return $minimumPercentCovered; | ||
} | ||
|
||
function handleOutput($lines, $minimumPercentCovered) | ||
{ | ||
$coveredLines = count($lines['coveredLines'], COUNT_RECURSIVE); | ||
$uncoveredLines = count($lines['uncoveredLines'], COUNT_RECURSIVE); | ||
|
||
if ($coveredLines + $uncoveredLines == 0) { | ||
exit(0); | ||
} | ||
|
||
$percentCovered = 100 * ($coveredLines / ($coveredLines + $uncoveredLines)); | ||
if ($percentCovered >= $minimumPercentCovered) { | ||
exit(0); | ||
} | ||
|
||
echo "$percentCovered% Covered, Missed lines " . PHP_EOL; | ||
print_r($lines['uncoveredLines']); | ||
exit(2); | ||
} |
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,60 @@ | ||
<?php | ||
namespace exussum12\CoverageChecker\FileMatchers; | ||
|
||
use exussum12\CoverageChecker\FileMatcher; | ||
use exussum12\CoverageChecker\Exceptions\FileNotFound; | ||
|
||
/** | ||
* Class FileMapper | ||
* @package exussum12\CoverageChecker\FileMatchers | ||
*/ | ||
class FileMapper implements FileMatcher | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $originalPath; | ||
/** | ||
* @var string | ||
*/ | ||
protected $newPath; | ||
|
||
/** | ||
* FileMapper constructor. | ||
* @param string $originalPath | ||
* @param string $newPath | ||
*/ | ||
public function __construct($originalPath, $newPath) | ||
{ | ||
$this->originalPath = $originalPath; | ||
$this->newPath = $newPath; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function match($needle, array $haystack) | ||
{ | ||
foreach ($haystack as $file) { | ||
if ($this->checkMapping($file, $needle)) { | ||
return $file; | ||
} | ||
} | ||
|
||
throw new FileNotFound(); | ||
} | ||
|
||
/** | ||
* @param string $file | ||
* @param string $needle | ||
* @return bool | ||
*/ | ||
private function checkMapping($file, $needle) | ||
{ | ||
return $file == str_replace( | ||
$this->originalPath, | ||
$this->newPath, | ||
$needle | ||
); | ||
} | ||
} |
Oops, something went wrong.