Skip to content

test: improve the tests for in_array#21087

Open
jorgsowa wants to merge 5 commits intophp:masterfrom
jorgsowa:test/improve-tests-for-in_array
Open

test: improve the tests for in_array#21087
jorgsowa wants to merge 5 commits intophp:masterfrom
jorgsowa:test/improve-tests-for-in_array

Conversation

@jorgsowa
Copy link
Contributor

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.

Copy link
Member

@Girgias Girgias left a 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.

@jorgsowa jorgsowa force-pushed the test/improve-tests-for-in_array branch from a7dd7b0 to c64920f Compare January 30, 2026 16:26
@jorgsowa
Copy link
Contributor Author

Is splitting reference-value data into a separate test appropriate?

I added descriptions to each iteration to make the test results easier to review.
Additionally, I added an enum/object test cases, as it was missing before. I can

Comment on lines 20 to 41
$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,
);
Copy link
Member

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...

Comment on lines 52 to 57
//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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//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 (
Copy link
Member

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.

Suggested change
$array_compare = array (
$values = array (

Copy link
Member

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.

@jorgsowa jorgsowa force-pushed the test/improve-tests-for-in_array branch from 99b25bb to 0a40431 Compare February 7, 2026 00:08
@jorgsowa
Copy link
Contributor Author

jorgsowa commented Feb 7, 2026

Thanks for the review. I understand you now.

All feedback has been addressed: the large test was split into 9 files inside in_array/ subfolder with a shared .inc for the descriptive-key dictionary (renamed to $values), and enum test cases were added as well.

@jorgsowa jorgsowa force-pushed the test/improve-tests-for-in_array branch from 54dcc04 to 77d99c4 Compare February 7, 2026 00:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants