Skip to content

Array subset works with flat arrays;#2781

Closed
askovron wants to merge 1 commit into
sebastianbergmann:5.6from
askovron:assertArrayAccess_flat_arrays
Closed

Array subset works with flat arrays;#2781
askovron wants to merge 1 commit into
sebastianbergmann:5.6from
askovron:assertArrayAccess_flat_arrays

Conversation

@askovron

Copy link
Copy Markdown

Add possibility to check flat arrays within assertArrayContains

Fixes #2069

return 0;
}
}
if ($other_value > $subset_value) return 1;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Inline control structures are not allowed

@sebastianbergmann

Copy link
Copy Markdown
Owner

Thank you for your contribution. I appreciate the time you invested in preparing this pull request. However, I have decided not to merge it because I do not understand the issue (see #2069 (comment)) you're trying to solve here.

@askovron

askovron commented Feb 2, 2018

Copy link
Copy Markdown
Author

@sebastianbergmann

(1) The issue was (and is) that the arraySubset assertion passes only when the subset is located in the very beginning of the array.

Array = ['a', 'b', 'c']
Valid subset = ['a', 'b']
Invalid subset = ['b', 'c']

(2) The second issue is that the subset must be in the same order in both suubset and the original array.

Array = ['a', 'b', 'c']
Valid subset = ['a', 'b']
Invalid subset = ['b', 'a']

FYI. During tests had been running on this branch there were some errors not related to this feature.

@BonBonSlick

BonBonSlick commented Dec 7, 2018

Copy link
Copy Markdown

I am faced issues with auto indexed arrays today, what was solution?

"phpunit/phpunit": "^7.1",

  $content  = \json_decode($response->getContent(), true);
  static::assertArraySubset(
    [
      [
        'email' => 'member@email.com',

Fails sometimes, because array with email has different int index.
Nothing in docs about that and I dont see any more asserts for this case, no comments in this thread with solution assert axmaple.

https://phpunit.de/manual/6.5/en/appendixes.assertions.html#appendixes.assertions.assertArraySubset

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Apr 28, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants