Skip to content

Commit

Permalink
Merge branch 'master' into feature/ignore-code-by-regex
Browse files Browse the repository at this point in the history
  • Loading branch information
sanmai committed Sep 14, 2020
2 parents 8a1910c + 2a2a203 commit cb789a0
Show file tree
Hide file tree
Showing 11 changed files with 329 additions and 31 deletions.
64 changes: 47 additions & 17 deletions src/Engine.php
Expand Up @@ -45,6 +45,7 @@
use Infection\Metrics\MinMsiChecker;
use Infection\Metrics\MinMsiCheckFailed;
use Infection\Mutation\MutationGenerator;
use Infection\PhpParser\Visitor\IgnoreNode\NodeIgnorer;
use Infection\Process\Runner\InitialTestsFailed;
use Infection\Process\Runner\InitialTestsRunner;
use Infection\Process\Runner\MutationTestingRunner;
Expand Down Expand Up @@ -128,41 +129,70 @@ private function runInitialTestSuite(): void
return;
}

$initialTestSuitProcess = $this->initialTestsRunner->run(
$initialTestSuiteProcess = $this->initialTestsRunner->run(
$this->config->getTestFrameworkExtraOptions(),
explode(' ', (string) $this->config->getInitialTestsPhpOptions()),
$this->getInitialTestsPhpOptionsArray(),
$this->config->shouldSkipCoverage()
);

if (!$initialTestSuitProcess->isSuccessful()) {
throw InitialTestsFailed::fromProcessAndAdapter($initialTestSuitProcess, $this->adapter);
if (!$initialTestSuiteProcess->isSuccessful()) {
throw InitialTestsFailed::fromProcessAndAdapter($initialTestSuiteProcess, $this->adapter);
}

$this->coverageChecker->checkCoverageHasBeenGenerated(
$initialTestSuitProcess->getCommandLine(),
$initialTestSuitProcess->getOutput()
$initialTestSuiteProcess->getCommandLine(),
$initialTestSuiteProcess->getOutput()
);

// Limit the memory used for the mutation processes based on the memory used for the initial
// test run
$this->memoryLimiter->limitMemory($initialTestSuitProcess->getOutput(), $this->adapter);
/*
* Limit the memory used for the mutation processes based on the memory
* used for the initial test run.
*/
$this->memoryLimiter->limitMemory($initialTestSuiteProcess->getOutput(), $this->adapter);
}

/**
* @return string[]
*/
private function getInitialTestsPhpOptionsArray(): array
{
return explode(' ', (string) $this->config->getInitialTestsPhpOptions());
}

private function runMutationAnalysis(): void
{
$mutations = $this->mutationGenerator->generate(
$this->config->mutateOnlyCoveredCode(),
$this->adapter instanceof IgnoresAdditionalNodes
? $this->adapter->getNodeIgnorers()
: []
$this->getNodeIgnorers()
);

$this->mutationTestingRunner->run(
$mutations,
$this->getFilteredExtraOptionsForMutant()
);
}

$actualExtraOptions = $this->config->getTestFrameworkExtraOptions();
/**
* @return NodeIgnorer[]
*/
private function getNodeIgnorers(): array
{
if ($this->adapter instanceof IgnoresAdditionalNodes) {
return $this->adapter->getNodeIgnorers();
}

$filteredExtraOptionsForMutant = $this->adapter instanceof ProvidesInitialRunOnlyOptions
? $this->testFrameworkExtraOptionsFilter->filterForMutantProcess($actualExtraOptions, $this->adapter->getInitialRunOnlyOptions())
: $actualExtraOptions;
return [];
}

private function getFilteredExtraOptionsForMutant(): string
{
if ($this->adapter instanceof ProvidesInitialRunOnlyOptions) {
return $this->testFrameworkExtraOptionsFilter->filterForMutantProcess(
$this->config->getTestFrameworkExtraOptions(),
$this->adapter->getInitialRunOnlyOptions()
);
}

$this->mutationTestingRunner->run($mutations, $filteredExtraOptionsForMutant);
return $this->config->getTestFrameworkExtraOptions();
}
}
3 changes: 2 additions & 1 deletion src/Metrics/MinMsiChecker.php
Expand Up @@ -39,8 +39,9 @@

/**
* @internal
* @final
*/
final class MinMsiChecker
class MinMsiChecker
{
private const VALUE_OVER_REQUIRED_TOLERANCE = 2;

Expand Down
3 changes: 2 additions & 1 deletion src/Mutation/MutationGenerator.php
Expand Up @@ -49,8 +49,9 @@

/**
* @internal
* @final
*/
final class MutationGenerator
class MutationGenerator
{
private $traceProvider;
private $mutators;
Expand Down
10 changes: 5 additions & 5 deletions src/Process/Runner/InitialTestsFailed.php
Expand Up @@ -47,31 +47,31 @@
final class InitialTestsFailed extends Exception
{
public static function fromProcessAndAdapter(
Process $initialTestSuitProcess,
Process $initialTestSuiteProcess,
TestFrameworkAdapter $testFrameworkAdapter
): self {
$testFrameworkKey = $testFrameworkAdapter->getName();

$lines = [
'Project tests must be in a passing state before running Infection.',
$testFrameworkAdapter->getInitialTestsFailRecommendations($initialTestSuitProcess->getCommandLine()),
$testFrameworkAdapter->getInitialTestsFailRecommendations($initialTestSuiteProcess->getCommandLine()),
sprintf(
'%s reported an exit code of %d.',
$testFrameworkKey,
$initialTestSuitProcess->getExitCode()
$initialTestSuiteProcess->getExitCode()
),
sprintf(
'Refer to the %s\'s output below:',
$testFrameworkKey
),
];

if ($stdOut = $initialTestSuitProcess->getOutput()) {
if ($stdOut = $initialTestSuiteProcess->getOutput()) {
$lines[] = 'STDOUT:';
$lines[] = $stdOut;
}

if ($stdError = $initialTestSuitProcess->getErrorOutput()) {
if ($stdError = $initialTestSuiteProcess->getErrorOutput()) {
$lines[] = 'STDERR:';
$lines[] = $stdError;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Process/Runner/InitialTestsRunner.php
Expand Up @@ -44,8 +44,9 @@

/**
* @internal
* @final
*/
final class InitialTestsRunner
class InitialTestsRunner
{
private $processBuilder;
private $eventDispatcher;
Expand Down
3 changes: 2 additions & 1 deletion src/Process/Runner/MutationTestingRunner.php
Expand Up @@ -52,8 +52,9 @@

/**
* @internal
* @final
*/
final class MutationTestingRunner
class MutationTestingRunner
{
private $processFactory;
private $mutantFactory;
Expand Down
3 changes: 2 additions & 1 deletion src/Resource/Memory/MemoryLimiter.php
Expand Up @@ -44,8 +44,9 @@

/**
* @internal
* @final
*/
final class MemoryLimiter
class MemoryLimiter
{
private $fileSystem;
private $phpIniPath;
Expand Down
3 changes: 2 additions & 1 deletion src/TestFramework/Coverage/CoverageChecker.php
Expand Up @@ -50,8 +50,9 @@

/**
* @internal
* @final
*/
final class CoverageChecker
class CoverageChecker
{
private const PHPUNIT = 'phpunit';
private const CODECEPTION = 'codeception';
Expand Down
3 changes: 2 additions & 1 deletion src/TestFramework/TestFrameworkExtraOptionsFilter.php
Expand Up @@ -42,8 +42,9 @@

/**
* @internal
* @final
*/
final class TestFrameworkExtraOptionsFilter
class TestFrameworkExtraOptionsFilter
{
/**
* @param string[] $initialRunOnlyOptions
Expand Down
2 changes: 0 additions & 2 deletions tests/phpunit/AutoReview/ProjectCode/ProjectCodeProvider.php
Expand Up @@ -50,7 +50,6 @@
use Infection\Console\OutputFormatter\OutputFormatter;
use Infection\Console\OutputFormatter\ProgressFormatter;
use Infection\Console\XdebugHandler;
use Infection\Engine;
use Infection\Event\Subscriber\MutationGeneratingConsoleLoggerSubscriber;
use Infection\Event\Subscriber\NullSubscriber;
use Infection\FileSystem\DummyFileSystem;
Expand Down Expand Up @@ -101,7 +100,6 @@ final class ProjectCodeProvider
MutationGeneratingConsoleLoggerSubscriber::class,
TestFrameworkTypes::class,
NodeMutationGenerator::class,
Engine::class,
NonExecutableFinder::class,
AdapterInstaller::class,
DetectionStatus::class,
Expand Down

0 comments on commit cb789a0

Please sign in to comment.