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

Add failing test regarding missing input #78

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

nochso
Copy link
Contributor

@nochso nochso commented Jan 26, 2016

Sadly this reopens #75

Given no configuration and no CLI input, Symfony will happily validate the InputDefinition.

Caused by removing the array_filter using is_null while fixing the InputOption>config issue.

@nochso
Copy link
Contributor Author

nochso commented Jan 26, 2016

Added my attempt of fixing it.

@nochso
Copy link
Contributor Author

nochso commented Jan 26, 2016

Pondered some more, the obvious solution is to check if the option is VALUE_NONE and handle that.

See the latest revision. It should make sense, the tests are passing and InspectableArgvInput can be removed.

@tomzx
Copy link
Owner

tomzx commented Jan 27, 2016

The code below works as well. The issue with the bug is that we set all arguments and options in the Input (in our case InspectableArgvInput) even if the configuration doesn't have them set. So we basically have the same problem we had with Input, but with the configuration class, that is, being able to determine if a key is set, and only then using that value.

Interestingly enough, I looked at the code of Config which is an issue in my opinion:

    public function has($key)
    {
        return !is_null($this->get($key));
    }

Here's a fix that makes your test pass without having to use the InputDefinition. If you don't see anything wrong with this fix, I'll take your test in your commit above and submit this change.

    public function merge(InputInterface $input, Configuration $config)
    {
        foreach ($input->getArguments() as $argument => $value) {
            if ($input->hasArgumentSet($argument)) {
                $config->set($argument, $value);
            } else {
                $value = $config->get($argument);
                if ($value) {
                    $input->setArgument($argument, $value);
                }

            }
        }

        foreach ($input->getOptions() as $option => $value) {
            if ($input->hasOptionSet($option)) {
                $config->set($option, $value);
            } else {
                $value = $config->get($option);
                if ($value) {
                    $input->setOption($option, $value);
                }
            }
        }
    }

Edit: I just saw your second commit is exactly this code. I guess it doesn't cover all cases? (at least it covers the one given in the test...)

@nochso
Copy link
Contributor Author

nochso commented Jan 27, 2016

The 2nd commit is OK, however the 3rd should be more clear. It's checking for the actual root cause instead of using InspectableArgvInput to get around the existing behaviour.

IMO you should clearly define the desired behaviour first. "Overriding VALUE_NONE options" is tricky in itself. IMO they should simply not be used as it's confusing: I can NOT override a VALUE_NONE from the CLI the way we want to use it with Configuration. Not the first time there's confusion surrounding symfony/console arguments/options though :/

@tomzx
Copy link
Owner

tomzx commented Jan 27, 2016

I'm not sure I'm following you. Can't a InputOption::VALUE_NONE be set to true/false, thus allowing us to override them via the configuration? If not, could you provide an example/test case?

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.

2 participants