Skip to content

Commit

Permalink
Merge pull request #103 from Roave/feature/cleanup-mutants
Browse files Browse the repository at this point in the history
Remove all mutation test escaped mutants
  • Loading branch information
Ocramius authored Aug 23, 2018
2 parents e22ffba + 3b853b2 commit 347c99d
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:

- stage: Mutation Tests
php: 7.2
script: vendor/bin/infection
script: vendor/bin/infection --min-msi=100 --min-covered-msi=100

- stage: Verify BC Breaks
php: 7.2
Expand Down
5 changes: 5 additions & 0 deletions infection.json.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@
},
"logs": {
"text": "infection-log.txt"
},
"mutators": {
"@default": true,
"IdenticalEqual": false,
"NotIdenticalNotEqual": false
}
}
16 changes: 9 additions & 7 deletions src/Command/AssertBackwardsCompatible.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function execute(InputInterface $input, OutputInterface $output) : int

$toRevision = $this->parseRevision->fromStringForRepository($input->getOption('to'), $sourceRepo);

$stdErr->writeln(sprintf('Comparing from %s to %s...', (string) $fromRevision, (string) $toRevision));
$stdErr->writeln(sprintf('Comparing from %s to %s...', $fromRevision, $toRevision));

$fromPath = $this->git->checkout($sourceRepo, $fromRevision);
$toPath = $this->git->checkout($sourceRepo, $toRevision);
Expand All @@ -164,11 +164,11 @@ public function execute(InputInterface $input, OutputInterface $output) : int
),
$this->makeComposerInstallationReflector->__invoke(
$fromPath->__toString(),
$this->locateDependencies->__invoke((string) $fromPath)
$this->locateDependencies->__invoke($fromPath->__toString())
),
$this->makeComposerInstallationReflector->__invoke(
$toPath->__toString(),
$this->locateDependencies->__invoke((string) $toPath)
$this->locateDependencies->__invoke($toPath->__toString())
)
);

Expand Down Expand Up @@ -206,10 +206,11 @@ private function printOutcomeAndExit(Changes $changes, OutputInterface $stdErr)
*/
private function parseRevisionFromInput(InputInterface $input, CheckedOutRepository $repository) : Revision
{
return $this->parseRevision->fromStringForRepository(
(string) $input->getOption('from'),
$repository
);
$from = $input->getOption('from');

Assert::that($from)->string();

return $this->parseRevision->fromStringForRepository($from, $repository);
}

private function determineFromRevisionFromRepository(
Expand All @@ -218,6 +219,7 @@ private function determineFromRevisionFromRepository(
) : Revision {
$versions = $this->getVersions->fromRepository($repository);

// @TODO add a test around the 0 limit
Assert::that($versions->count())
->greaterThan(0, 'Could not detect any released versions for the given repository');

Expand Down
2 changes: 1 addition & 1 deletion src/Formatter/MarkdownPipedToSymfonyConsoleFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private function convertFilteredChangesToMarkdownBulletList(callable $filterFunc
{
return array_map(
function (Change $change) : string {
return ' - ' . str_replace(['ADDED: ', 'CHANGED: ', 'REMOVED: '], '', trim((string) $change)) . "\n";
return ' - ' . str_replace(['ADDED: ', 'CHANGED: ', 'REMOVED: '], '', trim($change->__toString())) . "\n";
},
array_filter($changes, $filterFunction)
);
Expand Down
2 changes: 1 addition & 1 deletion src/Formatter/SymfonyConsoleTextFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function write(Changes $changes) : void
{
/** @var Change $change */
foreach ($changes as $change) {
$this->output->writeln((string) $change);
$this->output->writeln($change->__toString());
}
}
}
2 changes: 1 addition & 1 deletion src/Git/GetVersionCollectionFromGitRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ final class GetVersionCollectionFromGitRepository implements GetVersionCollectio
public function fromRepository(CheckedOutRepository $checkedOutRepository) : VersionsCollection
{
$output = (new Process(['git', 'tag', '-l']))
->setWorkingDirectory((string) $checkedOutRepository)
->setWorkingDirectory($checkedOutRepository->__toString())
->mustRun()
->getOutput();

Expand Down
18 changes: 7 additions & 11 deletions src/Git/GitCheckoutRevisionToTemporaryPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
use Symfony\Component\Process\Exception\RuntimeException as ProcessRuntimeException;
use Symfony\Component\Process\Process;
use function file_exists;
use function is_dir;
use function sprintf;
use function sys_get_temp_dir;
use function uniqid;

final class GitCheckoutRevisionToTemporaryPath implements PerformCheckoutOfRevision
{
Expand All @@ -20,9 +18,7 @@ final class GitCheckoutRevisionToTemporaryPath implements PerformCheckoutOfRevis

public function __construct(?callable $uniquenessFunction = null)
{
$this->uniquenessFunction = $uniquenessFunction ?? function (string $nonUniqueThing) : string {
return uniqid($nonUniqueThing, true);
};
$this->uniquenessFunction = $uniquenessFunction ?? 'uniqid';
}

/**
Expand All @@ -33,8 +29,8 @@ public function checkout(CheckedOutRepository $sourceRepository, Revision $revis
{
$checkoutDirectory = $this->generateTemporaryPathFor($revision);

(new Process(['git', 'clone', (string) $sourceRepository, $checkoutDirectory]))->mustRun();
(new Process(['git', 'checkout', (string) $revision]))->setWorkingDirectory($checkoutDirectory)->mustRun();
(new Process(['git', 'clone', $sourceRepository, $checkoutDirectory]))->mustRun();
(new Process(['git', 'checkout', $revision]))->setWorkingDirectory($checkoutDirectory)->mustRun();

return CheckedOutRepository::fromPath($checkoutDirectory);
}
Expand All @@ -45,7 +41,7 @@ public function checkout(CheckedOutRepository $sourceRepository, Revision $revis
*/
public function remove(CheckedOutRepository $checkedOutRepository) : void
{
(new Process(['rm', '-rf', (string) $checkedOutRepository]))->mustRun();
(new Process(['rm', '-rf', $checkedOutRepository]))->mustRun();
}

/**
Expand All @@ -54,12 +50,12 @@ public function remove(CheckedOutRepository $checkedOutRepository) : void
private function generateTemporaryPathFor(Revision $revision) : string
{
$uniquePathGenerator = $this->uniquenessFunction;
$checkoutDirectory = sys_get_temp_dir() . '/api-compare-' . $uniquePathGenerator((string) $revision . '_');
$checkoutDirectory = sys_get_temp_dir() . '/api-compare-' . $uniquePathGenerator($revision . '_');

if (file_exists($checkoutDirectory) || is_dir($checkoutDirectory)) {
if (file_exists($checkoutDirectory)) {
throw new RuntimeException(sprintf(
'Tried to check out revision "%s" to directory "%s" which already exists',
(string) $revision,
$revision->__toString(),
$checkoutDirectory
));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Git/GitParseRevision.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function fromStringForRepository(string $something, CheckedOutRepository
{
return Revision::fromSha1(
(new Process(['git', 'rev-parse', $something]))
->setWorkingDirectory((string) $repository)
->setWorkingDirectory($repository->__toString())
->mustRun()
->getOutput()
);
Expand Down
23 changes: 21 additions & 2 deletions test/unit/Command/AssertBackwardsCompatibleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,11 @@ public function testExecuteWithDefaultRevisionsNotProvidedAndNoDetectedTags() :
$this->compare->execute($this->input, $this->output);
}

public function testExecuteWithDefaultRevisionsNotProvided() : void
/** @dataProvider validVersionsCollections */
public function testExecuteWithDefaultRevisionsNotProvided(VersionsCollection $versions) : void
{
$fromSha = sha1('fromRevision', false);
$toSha = sha1('toRevision', false);
$versions = new VersionsCollection(Version::fromString('1.0.0'), Version::fromString('1.0.1'));
$pickedVersion = Version::fromString('1.0.0');

$this->input->expects(self::any())->method('getOption')->willReturnMap([
Expand Down Expand Up @@ -382,4 +382,23 @@ public function testExecuteWithDefaultRevisionsNotProvided() : void

self::assertSame(0, $this->compare->execute($this->input, $this->output));
}

/** @return VersionsCollection[][] */
public function validVersionsCollections() : array
{
return [
[new VersionsCollection(
Version::fromString('1.0.0'),
Version::fromString('1.0.1'),
Version::fromString('1.0.2')
),
],
[new VersionsCollection(
Version::fromString('1.0.0'),
Version::fromString('1.0.1')
),
],
[new VersionsCollection(Version::fromString('1.0.0'))],
];
}
}

0 comments on commit 347c99d

Please sign in to comment.