Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore bogus "not installed" exception from PackageVersions #1151

Merged
merged 3 commits into from
Mar 11, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@
use Infection\Command\InfectionCommand;
use Infection\Console\ConsoleOutput as InfectionConsoleOutput;
use Infection\Container;
use OutOfBoundsException;
use PackageVersions\Versions;
use const PHP_SAPI;
use function preg_quote;
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 +62,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 +83,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 .*' . preg_quote(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
Copy link
Member Author

@sanmai sanmai Mar 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This happens in very peculiar circumstances which, I think, just not worth the time to be reproduced, even with an E2E test. Therefore not covered by default.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what version will be displayed there? Wasn't a case also when you were globally installing infection with --no-scripts?

Copy link
Member Author

@sanmai sanmai Mar 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With --no-scripts there's no exception here, IIRC. That issue is still open #876


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

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