Skip to content

Allow empty subset arrays #14

Open
@codekandis

Description

@codekandis

I have several integration tests where I have to test an array is a subset of another array. These tests are implemented in a generic way for a specific case. The test is fed by data providers. The mentioned subset arrays can be empty in several data sets of the data provider.

Actually your library doesn't support empty subsets and throws an exception. So I could have an conditional assert on "if subset !== empty then assertArraySubset()". But I'd prefer the possibility to test for empty subsets while the subset should always be assumed as known if it's empty or whatever values it contains by the writer of the test. So an error on an empty subset restricts the testing abilities.

Edit

This discovery makes it more a bug report over a feature request.

If I test an empty subset array against an empty array no exception will be thrown which makes its behaviour inconsequent.

Activity

rdohms

rdohms commented on Dec 1, 2020

@rdohms
Owner

Original code is not mine so i'm also getting familiar with it.

I agree inconsistency is bad, so let's outline some cases:

  • empty array subset
  • empty target array
  • both empty

Deep down these are interesting cases, as empty subset will always be contained in any target array, and an empty array will never contain any subset. Empty and Empty is a weird case where it can return true/false based on which side you are looking at.

It feels to me that throwing an exception for any of these cases is a good idea, as they all look unintentional. That does indeed mean that they are not resilient to empty arrays that may happen.

What if:

  • empty subset: always true
  • empty target: always false
  • both: throw exception

Does this seem reasonable? alternative being exceptions to all cases. (have not looked into code to verify validity)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @rdohms@codekandis

        Issue actions

          Allow empty subset arrays · Issue #14 · rdohms/phpunit-arraysubset-asserts