-
Notifications
You must be signed in to change notification settings - Fork 39
Do not pass arguments using default values to the Filter\fun function #89
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
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.
Good. This will not change the default behavior.
Could you also add a small test that proves the correctness?
src/Encoding/FilteredStream.php
Outdated
@@ -57,8 +57,20 @@ | |||
*/ | |||
public function __construct(StreamInterface $stream, $readFilterOptions = null, $writeFilterOptions = null) | |||
{ | |||
$this->readFilterCallback = Filter\fun($this->readFilter(), $readFilterOptions); | |||
$this->writeFilterCallback = Filter\fun($this->writeFilter(), $writeFilterOptions); | |||
switch (func_num_args()) { |
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.
if we pass explicit null to the constructor, this will fail right? what if i want write filter options but no read filter options? we could instead do:
if ($readFilterOptions) {
$this->readFilterCallback = Filter\fun($this->readFilter(), $readFilterOptions);
} else {
$this->readFilterCallback = Filter\fun($this->readFilter());
}
and the same for write filter
thanks! can you please rebase on master? that will make the styleci issue go away. |
… user for the read/write filters
I've rebased on |
…lass to initialize the stream filter
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.
looking at this i am pretty sure its correct...
for the test: could you do a functional test that uses an actual file stream as a base and tests the various cases with it? or does file stream not expose the quirks about null for options?
@ste93cry what is the status on the test? |
Ping |
I've added a proof of concept for the unit tests, as I said some time go I never used PHPSpec so I don't know how to write tests with it. I saw that the |
@joelwurtz Please note the following part of my previous message:
Before merging you should double-check the tests I wrote because I'm not sure they work properly |
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.
Thank yuo
I think the tests looks good. |
I check them, it's good, nice job :) To be more clear, withtout the shouldThrow phpspec was not calling the constructor (as there is no test on it, so this was normal), however if you change shouldThrow to shouldNotThrow there you will see that there is an exception raised |
What's in this PR?
This PR addresses the fact that the
stream_filter_append
function does not necessarily acceptnull
as value of the$params
argument for all filters. Instead theFilteredStream
constructor always passed them to the function that in those cases throw the following error:The cause of this (it's an assumption I made based on my tests) is that it seems that some filters do not have
null
as default value for the$params
argument, for example theconvert.base64-encode
andconvert.base64-decode
filters have an empty array. To workaround the problem I applied the same fix that was made in clue/stream-filter#15 by using only the arguments that were explicitly passed from the user to the constructor of theFilteredStream
class.