Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assertArraySubset() does not work as expected #3240

Closed
rafrsr opened this issue Aug 3, 2018 · 3 comments
Closed

assertArraySubset() does not work as expected #3240

rafrsr opened this issue Aug 3, 2018 · 3 comments

Comments

@rafrsr
Copy link

rafrsr commented Aug 3, 2018

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.

@sebastianbergmann
Copy link
Owner

This might be what was mentioned in #3161 (comment).

To be honest, I do not know how this is expected to work as I never used assertArraySubset().

@marcioAlmada originally implemented assertArraySubset() (and most recently @pfrenssen did some work on it). I am not writing this to assign blame, simply to explain why I do not know how assertArraySubset() is expected to work.

If @pfrenssen really introduced a BC break with #3161 then, of course, this needs to be fixed (or reverted if it cannot be fixed).

@sebastianbergmann sebastianbergmann changed the title PHPUnit 7.3: assertArraySubset does not work as expected assertArraySubset() does not work as expected Aug 4, 2018
pfrenssen added a commit to ec-europa/phpunit that referenced this issue Aug 5, 2018
@pfrenssen
Copy link
Contributor

@rafrsr thanks for the report. I have made a test case out of your code: #3243. I was able to replicate the issue without having to use json_decode(json_encode($array)).

The good news is that there is already a PR that fixes this: #3186. I will add the test for this case to that PR to prove that this is conclusively fixed.

pfrenssen added a commit to ec-europa/phpunit that referenced this issue Aug 5, 2018
This proves that the bug reported in sebastianbergmann#3240 is also fixed in scope of this PR.
pfrenssen added a commit to ec-europa/phpunit that referenced this issue Aug 5, 2018
This proves that the bug reported in sebastianbergmann#3240 is also fixed in scope of this PR.
@sebastianbergmann
Copy link
Owner

I have reverted #3240 to fix this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants