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
Conversation
There was a problem hiding this 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.
Builds are failing because of #631. Otherwise all seems to be fine. |
src/Command/InfectionCommand.php
Outdated
@@ -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'); |
There was a problem hiding this comment.
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
.
infection/src/Config/InfectionConfig.php
Line 155 in 5b02e8e
return $this->config->testFramework ?? 'phpunit'; |
$this->config->testFramework
is empty when infection.json
does not exist. Because of
infection/src/Config/ConfigCreatorFacade.php
Lines 80 to 85 in 5b02e8e
} 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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
- It would resolve the issue with config initialization, because of a statically called method
- It would make code more expressive because what we want to do here is really getting a default TF
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
b541079
to
0d91b4e
Compare
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).