-
Notifications
You must be signed in to change notification settings - Fork 0
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 #9 from datashaman/feature/2-coverage
Add coverage
- Loading branch information
Showing
27 changed files
with
140 additions
and
26 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,3 +1,4 @@ | ||
/build/ | ||
/composer.lock | ||
/.phpcheck/ | ||
/php_errors.log | ||
|
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
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
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,57 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* This file is part of the phpcheck package. | ||
* | ||
* ©Marlin Forbes <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace Datashaman\PHPCheck\Reporters; | ||
|
||
use Datashaman\PHPCheck\CheckEvents; | ||
use Datashaman\PHPCheck\Events; | ||
use SebastianBergmann\CodeCoverage\CodeCoverage; | ||
use SebastianBergmann\CodeCoverage\Report\Html\Facade as HtmlFacade; | ||
|
||
class HtmlCoverageReporter extends Reporter | ||
{ | ||
protected $coverage; | ||
|
||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
CheckEvents::END => 'onEnd', | ||
CheckEvents::END_ALL => 'onEndAll', | ||
CheckEvents::START => 'onStart', | ||
CheckEvents::START_ALL => 'onStartAll', | ||
]; | ||
} | ||
|
||
public function onEnd(Events\EndEvent $event): void | ||
{ | ||
$this->coverage->stop(); | ||
} | ||
|
||
public function onEndAll(Events\EndAllEvent $event): void | ||
{ | ||
$writer = new HtmlFacade(); | ||
$writer->process($this->coverage, $this->input->getOption('coverage-html')); | ||
} | ||
|
||
public function onStart(Events\StartEvent $event): void | ||
{ | ||
$this->coverage->start($event->method->getName()); | ||
} | ||
|
||
public function onStartAll(Events\StartAllEvent $event): void | ||
{ | ||
if (!$this->input->getOption('coverage-html')) { | ||
$this->output->writeln('<error>You must specify a folder with --coverage-html</error>'); | ||
exit(1); | ||
} | ||
|
||
$this->coverage = new CodeCoverage(); | ||
$this->coverage->filter()->addDirectoryToWhitelist('./src'); | ||
} | ||
} |
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,61 @@ | ||
<?php declare(strict_types=1); | ||
/* | ||
* This file is part of the phpcheck package. | ||
* | ||
* ©Marlin Forbes <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
namespace Datashaman\PHPCheck\Reporters; | ||
|
||
use Datashaman\PHPCheck\CheckEvents; | ||
use Datashaman\PHPCheck\Events; | ||
use SebastianBergmann\CodeCoverage\CodeCoverage; | ||
use SebastianBergmann\CodeCoverage\Report\Text; | ||
|
||
class TextCoverageReporter extends Reporter | ||
{ | ||
protected $coverage; | ||
|
||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
CheckEvents::END => 'onEnd', | ||
CheckEvents::END_ALL => 'onEndAll', | ||
CheckEvents::START => 'onStart', | ||
CheckEvents::START_ALL => 'onStartAll', | ||
]; | ||
} | ||
|
||
public function onEnd(Events\EndEvent $event): void | ||
{ | ||
$this->coverage->stop(); | ||
} | ||
|
||
public function onEndAll(Events\EndAllEvent $event): void | ||
{ | ||
$writer = new Text(); | ||
|
||
|
||
if ($this->input->getOption('coverage-text')) { | ||
$output = $writer->process($this->coverage, false); | ||
file_put_contents($this->input->getOption('coverage-text'), $output); | ||
|
||
return; | ||
} | ||
|
||
print $writer->process($this->coverage, true); | ||
} | ||
|
||
public function onStart(Events\StartEvent $event): void | ||
{ | ||
$this->coverage->start($event->method->getName()); | ||
} | ||
|
||
public function onStartAll(Events\StartAllEvent $event): void | ||
{ | ||
$this->coverage = new CodeCoverage(); | ||
$this->coverage->filter()->addDirectoryToWhitelist('./src'); | ||
} | ||
} |
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