Skip to content

Commit

Permalink
Merge branch 'master' into feature/unwrap-array-splice
Browse files Browse the repository at this point in the history
  • Loading branch information
maks-rafalko committed Jan 11, 2019
2 parents d46a753 + 3ec02da commit 778af29
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 14 deletions.
28 changes: 28 additions & 0 deletions src/Command/InfectionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
use Infection\Process\Runner\MutationTestingRunner;
use Infection\Process\Runner\TestRunConstraintChecker;
use Infection\TestFramework\Coverage\CodeCoverageData;
use Infection\TestFramework\Coverage\CoverageDoesNotExistException;
use Infection\TestFramework\HasExtraNodeVisitors;
use Infection\TestFramework\PhpSpec\PhpSpecExtraOptions;
use Infection\TestFramework\PhpUnit\Coverage\CoverageXmlParser;
Expand All @@ -61,6 +62,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Process\Process;

/**
* @internal
Expand Down Expand Up @@ -236,6 +238,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
return 1;
}

$this->assertCodeCoverageExists($initialTestSuitProcess, $testFrameworkKey);

$container->get('memory.limit.applier')->applyMemoryLimitFromProcess($initialTestSuitProcess, $adapter);

$codeCoverageData = $this->getCodeCoverageData($testFrameworkKey);
Expand Down Expand Up @@ -367,4 +371,28 @@ private function runConfigurationCommand(Locator $locator): void
}
}
}

private function assertCodeCoverageExists(Process $initialTestsProcess, string $testFrameworkKey): void
{
$coverageDir = $this->getContainer()->get(sprintf('coverage.dir.%s', $testFrameworkKey));

$coverageIndexFilePath = $coverageDir . '/' . CodeCoverageData::COVERAGE_INDEX_FILE_NAME;

$processInfo = sprintf(
'%sCommand line: %s%sProcess Output: %s',
PHP_EOL,
$initialTestsProcess->getCommandLine(),
PHP_EOL,
$initialTestsProcess->getOutput()
);

if (!file_exists($coverageIndexFilePath)) {
throw CoverageDoesNotExistException::with(
$coverageIndexFilePath,
$testFrameworkKey,
\dirname($coverageIndexFilePath, 2),
$processInfo
);
}
}
}
20 changes: 10 additions & 10 deletions src/Finder/TestFrameworkFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,23 +134,23 @@ private function findTestFramework(): string
return $this->customPath;
}

/*
* There's a glitch where ExecutableFinder would find a non-executable
* file on Windows, even if there's a proper executable .bat by its side.
* Therefore we have to explicitly look for a .bat first.
*/
$candidates = [
$this->testFrameworkName . '.bat',
$this->testFrameworkName,
$this->testFrameworkName . '.phar',
];
$candidates = [];

if ($this->testFrameworkName === TestFrameworkTypes::PHPUNIT) {
$candidates[] = 'simple-phpunit.bat';
$candidates[] = 'simple-phpunit';
$candidates[] = 'simple-phpunit.phar';
}

/*
* There's a glitch where ExecutableFinder would find a non-executable
* file on Windows, even if there's a proper executable .bat by its side.
* Therefore we have to explicitly look for a .bat first.
*/
$candidates[] = $this->testFrameworkName . '.bat';
$candidates[] = $this->testFrameworkName;
$candidates[] = $this->testFrameworkName . '.phar';

$finder = new ExecutableFinder();

$cwd = getcwd();
Expand Down
2 changes: 1 addition & 1 deletion src/Mutator/Unwrap/UnwrapArraySlice.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This code is licensed under the BSD 3-Clause License.
*
* Copyright (c) 2017-2018, Maks Rafalko
* Copyright (c) 2017-2019, Maks Rafalko
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down
10 changes: 8 additions & 2 deletions src/TestFramework/Coverage/CoverageDoesNotExistException.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,17 @@
*/
final class CoverageDoesNotExistException extends InfectionException
{
public static function with(string $coverageIndexFilePath, string $testFrameworkKey, string $tempDir): self
public static function with(string $coverageIndexFilePath, string $testFrameworkKey, string $tempDir, string $processInfo = ''): self
{
$message = 'Code Coverage does not exist. File %s is not found. Check %s version Infection was run with and generated config files inside %s.';

if ($processInfo) {
$message .= $processInfo . PHP_EOL;
}

return new self(
sprintf(
'Code Coverage does not exist. File %s is not found. Check %s version Infection was run with and generated config files inside %s. Make sure to either: %s%s',
$message . ' Make sure to either: %s%s',
$coverageIndexFilePath,
$testFrameworkKey,
$tempDir,
Expand Down
2 changes: 1 addition & 1 deletion tests/Mutator/Unwrap/UnwrapArraySliceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This code is licensed under the BSD 3-Clause License.
*
* Copyright (c) 2017-2018, Maks Rafalko
* Copyright (c) 2017-2019, Maks Rafalko
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down

0 comments on commit 778af29

Please sign in to comment.