Skip to content

assertArraySubset() does not work as expected #3240

Closed
@rafrsr

Description

@rafrsr
Q A
PHPUnit version 7.3.0
PHP version 7.1
Installation Method Composer

After upgrade to phpunit 7.3 the assertArraySubset does not works as expected. I see that in this version great changes was made in this part; check the following example; works well with 7.2.7.

<?php

// the following lines emulate a response
// from other library that return a array of stdClass
$field1 = new \stdClass();
$field1->name = 'amount';
$field1->required = true;

$field2 = new \stdClass();
$field2->name = 'accountNumber';
$field2->required = true;

$dataArray = [$field1, $field2];
// end of emulation

//-> TEST

// convert the response in stdClass into associative array
$array = json_decode(json_encode($dataArray), true);

$subset = [
    [
        'name' => 'amount',
        'required' => true,
    ],
];

Assert::assertArraySubset($subset, $array);

The first part of the example is only for demonstration, really I use another library to get a JSON response (the library return that response using stdClass). But the point is, for some reason after convert this data to array the assertArraySubset does not work as expected; and the problem only happens with the boolean field, otherwise pass.

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

    Issue actions