-
Notifications
You must be signed in to change notification settings - Fork 8k
test: improve the tests for in_array #21087
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
base: master
Are you sure you want to change the base?
Conversation
Girgias
left a comment
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'd rather split this test into multiple ones because trying to verify that 200 iterations of a foreach is corret is just unreasonable.
a7dd7b0 to
c64920f
Compare
|
Is splitting reference-value data into a separate test appropriate? I added descriptions to each iteration to make the test results easier to review. |
| $array_compare = array ( | ||
| 4, | ||
| "4", | ||
| 4.00, | ||
| "b", | ||
| "5", | ||
| -2, | ||
| -2.0, | ||
| -2.98989, | ||
| "-.9", | ||
| "True", | ||
| "", | ||
| [], | ||
| NULL, | ||
| "ab", | ||
| "abcd", | ||
| 0.0, | ||
| -0, | ||
| "abcd\x00abcd\x00abcd", | ||
| Sample::A, | ||
| Sample::B, | ||
| ); |
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.
Why not have a dictionary where the key describes the value? So you don't need the "get_type" thing...
| //strict option OFF | ||
| var_dump(in_array($compare,$array)); | ||
| //strict option ON | ||
| var_dump(in_array($compare,$array,TRUE)); | ||
| //strict option OFF | ||
| var_dump(in_array($compare,$array,FALSE)); |
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.
| //strict option OFF | |
| var_dump(in_array($compare,$array)); | |
| //strict option ON | |
| var_dump(in_array($compare,$array,TRUE)); | |
| //strict option OFF | |
| var_dump(in_array($compare,$array,FALSE)); | |
| echo "in_array() strict=true\n"; | |
| var_dump(in_array($compare, $array, true)); | |
| echo "in_array() strict=false\n"; | |
| var_dump(in_array($compare, $array, false)); |
| $refVar7 = True; | ||
| $array = [&$refVar2, &$refVar, &$refVar3, &$refVar4, &$refVar5, &$refVar6, &$refVar7]; | ||
|
|
||
| $array_compare = array ( |
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.
The current name seems to imply this is the array we are comparing against, not the one that contains the test value.
| $array_compare = array ( | |
| $values = array ( |
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.
This test is already to long. Yes I know this is a test that has existed for a long time. But the guidelines that have existed forever now is for them to be small see https://php.github.io/php-src/miscellaneous/writing-tests.html#how-big-is-a-test-case
So I'd rather really split this massive test into smaller ones and even move them into a in_array sub folder so one can just run these tests.
Added more detailed descriptions to test iterations so it’s clear what the input is for each iteration. Additionally, I added a new test cases for an arrays containing references and enums.