zendframework / zend-inputfilter

InputFilter component from Zend Framework
BSD 3-Clause "New" or "Revised" License
64 stars 50 forks source link

Required does not work, when array is empty #167

Closed eweso closed 5 years ago

eweso commented 6 years ago

The first problem is, that hasValue always returns true, when a value is set, even, if the value is an empty array. So the first validation for the required filter will be skipped. The second problem is, that the isRequired is called within the foreach loop. But if the value is an empty array, the loop will never start, so isRequired will never triggered and the method will return the defaultValue true.

eweso commented 6 years ago

@webimpress Thank you for your feedback. I was on holiday until now. The point is, that I am really new to github and don't know, where the test files are and where I have to create one, to pass the checks. If someone could help me a little, we could fix that bug quickly.

weierophinney commented 6 years ago

@eweso The repository contains information on contributing, including how to run tests: https://github.com/zendframework/zend-inputfilter/blob/master/docs/CONTRIBUTING.md (BTW, tests are in the test/ subdirectory.)

If you need help writing tests, jump on the Slack and join the #contributors channel and start asking.

eweso commented 6 years ago

@weierophinney Thank you for the information! I will create the test class within the next two weeks and will pull the request again.

eweso commented 6 years ago

Okay, I still do not get, why the first test failed. There was already a test class in this repository. The basic behaviour hasn't changed. When I open the Details of coverage/coveralls it does not give me any information about missing test classes.

It just informs me, that some lines of codes have changed in the base repository and that Module.php ist missing. So am I right, that the coverage/coveralls does not fail because of the test, it fails because some lines of code were changed in the base branch, to which I wanted to pull my request?

If so, I think, I just have to update those files in my patch and the test will be successful?

eweso commented 6 years ago

@rkeet

This is a different case. I fixed a bug in the ArrayInput. You are talking about the InpuFilter.

When you have a Multi-Select for example and you use an ArrayInput with required in your InputFilter to validate the Multi-Select and there is no value selected, the ArrayInput returns at the moment true, because it does not handle the empty array as an empty value.

weierophinney commented 5 years ago

Thanks, @eweso!