Skip to content

Commit

Permalink
Ignore bogus "not installed" exception from PackageVersions
Browse files Browse the repository at this point in the history
  • Loading branch information
sanmai committed Mar 10, 2020
1 parent 42b7223 commit 530ad6f
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@
use Infection\Command\InfectionCommand;
use Infection\Console\ConsoleOutput as InfectionConsoleOutput;
use Infection\Container;
use OutOfBoundsException;
use PackageVersions\Versions;
use const PHP_SAPI;
use function Safe\preg_match;
use Symfony\Component\Console\Application as BaseApplication;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
Expand All @@ -59,6 +61,8 @@ final class Application extends BaseApplication
{
private const NAME = 'Infection - PHP Mutation Testing Framework';

private const PACKAGE_NAME = 'infection/infection';

private const INFECTION_PREFIX = 'INFECTION';

private const LOGO = '
Expand All @@ -78,7 +82,20 @@ final class Application extends BaseApplication

public function __construct(Container $container)
{
parent::__construct(self::NAME, Versions::getVersion('infection/infection'));
try {
$version = Versions::getVersion(self::PACKAGE_NAME);
// @codeCoverageIgnoreStart
} catch (OutOfBoundsException $e) {
if (preg_match('/package .*' . self::PACKAGE_NAME . '.* not installed/', $e->getMessage()) === 0) {
throw $e;
}

// We have a bogus exception: how can Infection be not installed if we're here?
$version = 'not-installed';
}
// @codeCoverageIgnoreEnd

parent::__construct(self::NAME, $version);

$this->container = $container;
$this->setDefaultCommand('run');
Expand Down

0 comments on commit 530ad6f

Please sign in to comment.