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

Use new config data when Infection has been executed at the first time #651

Merged
merged 2 commits into from Mar 29, 2019

Conversation

sanmai
Copy link
Member

@sanmai sanmai commented Mar 4, 2019

For one, InfectionConfig should be using known default values, but not access the configuration file that is non-existing at the time of configuration. For another, JsonFile should not continue as usual even if it is given a non-existing file.

Fixes #576

Kudos to @sidz for his effort in #577 (E2E test there is not exactly correct).

Copy link
Member

@sidz sidz left a comment

Choose a reason for hiding this comment

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

fyi: I've rebased my PR as well.

src/Console/InfectionContainer.php Outdated Show resolved Hide resolved
@sanmai
Copy link
Member Author

sanmai commented Mar 4, 2019

Builds are failing because of #631. Otherwise all seems to be fine.

@sanmai sanmai requested a review from maks-rafalko March 5, 2019 02:46
@@ -362,7 +362,7 @@ private function runConfigurationCommand(Locator $locator): void
$locator->locateOneOf(InfectionConfig::POSSIBLE_CONFIG_FILE_NAMES);
} catch (\Exception $e) {
$configureCommand = $this->getApplication()->find('configure');
$config = $this->getContainer()->get('infection.config');
$config = $this->getContainer()->get('infection.config.initial');
Copy link
Member

Choose a reason for hiding this comment

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

Seems like the only one reason why $config variable is used here is to get default test framework name ($config->getTestFramework()) when infection.json does not exist.

And since config does not exist, it always defaults to phpunit.

return $this->config->testFramework ?? 'phpunit';

$this->config->testFramework is empty when infection.json does not exist. Because of

} catch (LocatorException $e) {
// Generate an empty class to trigger `configure` command.
$content = new \stdClass();
$configLocation = getcwd();
}

If we replace $config->getTestFramework() with TestFrameworkTypes::PHPUNIT, this will be the same PR as #577

I think we don't need $config instance here at all.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've seen this done in #577, but decided to keep the current behavior. For one because if configuration values are coming from one source, then you don't have to walk around all code changing them. Change them in one place and be done. For another we may have an idea to guess the value in the future. Then, again, everything will be as ready for this as it is.

I think some of these reasons are behind why this was done like that in the first place.

Do you still think we should stick to PHPUnit defaulting with a plain constant?

Copy link
Member

Choose a reason for hiding this comment

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

Apologize for the late reply.

What you say is perfectly valid. The only issue with this particular line of code is that it was my mistake (read "bug") that I've added it here. Let me explain:

This is a commit that adds this config here: 2859730

From git commit message:

  • Use default test framework if neither CLI nor config has the value for it

So, all I wanted to do, is to use default test framework when it's impossible to get it neither from CLI option nor from the config.

Why was it a mistake? Because $config->getTestFramework() is intended to return a value from infection.json, not a default TF. It just has a fallback.

What I think would be the right solution:

instead of calling instance level method ->getTestFramework(), I would introduce a new static method InfectionConfig::getDefaultTestFramework() and call it here statically.

  1. It would resolve the issue with config initialization, because of a statically called method
  2. It would make code more expressive because what we want to do here is really getting a default TF

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, I got what you're thinking. This makes sense.

Copy link
Member Author

Choose a reason for hiding this comment

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

I went with TestFrameworkTypes::PHPUNIT for now.

(We can make an easy switch to InfectionConfig::getDefaultTestFramework() when it'll do anything in particular other than just returning TestFrameworkTypes::PHPUNIT.)

Copy link
Member

@maks-rafalko maks-rafalko left a comment

Choose a reason for hiding this comment

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

@sanmai @sidz any thought on the latest comments?

@maks-rafalko
Copy link
Member

Thank you @sanmai and @sidz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants