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
Update WizardComponent.php #24
Conversation
test type for $proceed
I'll leave this up to @bancer who's become far more active on this repo than I. Also, thank you @mlingureanu for your first contribution! |
@mlingureanu since this is your first contribution, can I ask you what this PR is trying to accomplish? What was the problem you ran into that made this fix necessary? |
The documentation says
I run into trouble, on unit tests, when instead of returning boolean, I need to force a redirect like |
Why are you getting an object? Sounds like a bug in your tests.
…On Fri, Mar 31, 2017 at 10:27 PM Manuel Lingureanu ***@***.***> wrote:
The documentation says
The process callback must return either true or false. If true, the wizard
will continue to the next step; if false, the user will remain on the step
and any validation errors will be presented.
I run into trouble, on unit tests, when instead of returning boolean, I
need to force a redirect like
return $this->redirect($url);
The problem is, this process callback will return an mocked object in unit
tests, and variable $proceed from wizard component will get this mocked
object instead of boolean value.
Next condition if ($proceed) without checking type, will assume this
object is true and will execute unwanted code.
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
<#24 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAEHQ39g5lZ2xdiYkZFj4yuDwybc7txRks5rreBJgaJpZM4MwI2x>
.
|
https://book.cakephp.org/2.0/en/development/testing.html#testing-controllers |
I am not convinced this change is needed while the same can be achieved by |
I'm too removed from the code to know how it works anymore, I just don't like strict comparisons to true unless you handle other truthy values differently (which this code doesn't) |
@@ -382,7 +382,7 @@ public function process($step) { | |||
} else { | |||
throw new NotImplementedException(sprintf(__('Process Callback not found. Please create Controller::%s', $processCallback))); | |||
} | |||
if ($proceed) { | |||
if ($proceed === true) { |
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.
$proceed from line 379 and line 381 should return always boolean, that's why it's a matter of best practices, to test type when dealing with booleans
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.
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.
Gotchas
When testing the return value of a function that can return either 0 or boolean false, like strpos(), always use === and !==, or you’ll run in to problems.
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.
That specifically talks about falsey values if they represent different things than null.
Again, I think something is wrong with your unit test. I need more context on how this code is called.
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.
Looks good for me. @ProLoser ?
Why does |
in WizardComponentTest.php at line 119
it's override default cakephp redirect method to not exit and to continue to how Bancer says
this is a snippet from my code:
I need this redirect, because I need to change param $restaurantId and method redirect from wizard don't allow params to be changed. |
by the way this comment |
I mean I'll leave it to bancer |
test type for $proceed