Problem/Motivation

assertArraySubset() is deprecated and will be removed in PHPUnit 9.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

mondrake created an issue. See original summary.

mondrake’s picture

Status: Active » Needs review
StatusFileSize
new1.3 KB

Kickoff patch, unsilencing the deprecation to see size of the changes needed.

Status: Needs review » Needs work

The last submitted patch, 2: 3126564-2.patch, failed testing. View results

longwave’s picture

Status: Needs work » Needs review
StatusFileSize
new9.77 KB

Had a go at the easier ones, run out of time now to do the rest,

Status: Needs review » Needs work

The last submitted patch, 4: 3126564-4.patch, failed testing. View results

jungle’s picture

It seems hard to get this done, as no alternative suggested.

  1. Should we adopt this package to bring it back, https://github.com/rdohms/phpunit-arraysubset-asserts
  2. Another good suggestion is to separate assertArraySubset() into assertAssocArraySubset($subset, $array, $strict=false) and assertIndexArraySubset($subset, $array, $order=false, $strict=false) from the comment here and Array Subset does not work as expected on indexed / flat arrays #3101, so maybe we should wrapper it as assertAssocArraySubset() to make it more clear.
  3. All I have to say on this subject I have written down here.

    If you rely on assertArraySubset() and its current behaviour and want to continue to use it then, please, go ahead, take the code, and put it into an extension. Not every assertion needs to be part of PHPUnit's standard distribution.

    -- From @sebastianbergmann's comment here

    It seems @sebastianbergmann, the creator of PHPUnit does not object to using it, he just did not want to maintain it in the standard distribution.

mondrake’s picture

Can we use assertSame instead of assertIdentical that is (should be) deprecated.

longwave’s picture

Status: Needs work » Needs review
StatusFileSize
new13.54 KB
new8.78 KB

The only complicated case is in EntityResourceTestBase:

        // Subset, not same, because we can e.g. send just the target_id for the
        // bundle in a PATCH or POST request; the response will include more
        // properties.
        $this->assertArraySubset($expected_stored_data, $modified_entity->get($field_name)->getValue(), TRUE);

Here we need to add our own recursive helper method.

jungle’s picture

Status: Needs review » Reviewed & tested by the community

Using assertContains() with string haystacks is deprecated and will not be supported in PHPUnit 9.

Unfortunately, all haystacks in the patch are arrays :p

Queued the patch against 9.0.x and it passed.

All good to me and learned from the patch, +1 to \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase::assertEntityArraySubset()

Thanks!

  • catch committed 09be91a on 9.1.x
    Issue #3126564 by longwave, mondrake: Replace usage of assertArraySubset...

  • catch committed 7a4eb6b on 9.0.x
    Issue #3126564 by longwave, mondrake: Replace usage of assertArraySubset...
catch’s picture

Version: 9.1.x-dev » 9.0.x-dev
Status: Reviewed & tested by the community » Fixed

Committed 09be91a and pushed to 9.1.x, cherry-picked to 9.0.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.