rdohms/phpunit-arraysubset-asserts

Allow empty subset arrays

codekandis opened this issue · 1 comments

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.

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)