-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
178 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Churn\Command\Helper; | ||
|
||
use Churn\Result\ResultAccumulator; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
class MaxScoreChecker | ||
{ | ||
|
||
/** | ||
* @var float|null | ||
*/ | ||
private $maxScoreThreshold; | ||
|
||
/** | ||
* @param float|null $maxScoreThreshold The max score threshold. | ||
*/ | ||
public function __construct(?float $maxScoreThreshold) | ||
{ | ||
$this->maxScoreThreshold = $maxScoreThreshold; | ||
} | ||
|
||
/** | ||
* @param InputInterface $input Input. | ||
* @param OutputInterface $output Output. | ||
* @param ResultAccumulator $report The report containing the scores. | ||
*/ | ||
public function isOverThreshold(InputInterface $input, OutputInterface $output, ResultAccumulator $report): bool | ||
{ | ||
$maxScore = $report->getMaxScore(); | ||
|
||
if (null === $this->maxScoreThreshold || null === $maxScore || $maxScore <= $this->maxScoreThreshold) { | ||
return false; | ||
} | ||
|
||
if ('text' === $input->getOption('format') || !empty($input->getOption('output'))) { | ||
$output->writeln('<error>Max score is over the threshold</>'); | ||
} | ||
|
||
return true; | ||
} | ||
} |
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 @@ | ||
maxScoreThreshold: 0.9 |
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,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Churn\Tests\Unit\Command\Helper; | ||
|
||
use Churn\Command\Helper\MaxScoreChecker; | ||
use Churn\Result\ResultAccumulator; | ||
use Churn\Tests\BaseTestCase; | ||
use Mockery as m; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class MaxScoreCheckerTest extends BaseTestCase | ||
{ | ||
|
||
/** | ||
* @test | ||
* @dataProvider provide_arguments | ||
*/ | ||
public function it_can_check_the_max_score( | ||
bool $expectedResult, | ||
?float $threshold, | ||
?float $maxScore, | ||
string $format = 'text', | ||
?string $output = null | ||
): void { | ||
$input = m::mock(InputInterface::class); | ||
$input->shouldReceive('getOption')->with('format')->andReturn($format); | ||
$input->shouldReceive('getOption')->with('output')->andReturn($output); | ||
|
||
$output = m::mock(OutputInterface::class); | ||
$output->shouldReceive('writeln'); | ||
|
||
$report = m::mock(ResultAccumulator::class); | ||
$report->shouldReceive('getMaxScore')->andReturn($maxScore); | ||
|
||
$checker = new MaxScoreChecker($threshold); | ||
|
||
$this->assertEquals( | ||
$expectedResult, | ||
$checker->isOverThreshold($input, $output, $report) | ||
); | ||
} | ||
|
||
public function provide_arguments(): iterable | ||
{ | ||
yield [false, null, null]; | ||
yield [false, 1, null]; | ||
yield [false, null, 1]; | ||
yield [false, 1, 0.1]; | ||
yield [true, 0.1, 1]; | ||
yield [true, 0.1, 1, 'text', '/tmp']; | ||
} | ||
} |
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