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

Comments

Projects
None yet
3 participants
@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

This comment has been minimized.

Copy link
Owner

sebastianbergmann commented Aug 4, 2018

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

This comment has been minimized.

Copy link
Contributor

pfrenssen commented Aug 5, 2018

@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

Add regression test for issue sebastianbergmann#3240.
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

Add regression test for issue sebastianbergmann#3240.
This proves that the bug reported in sebastianbergmann#3240 is also fixed in scope of this PR.
@sebastianbergmann

This comment has been minimized.

Copy link
Owner

sebastianbergmann commented Aug 7, 2018

I have reverted #3240 to fix this issue.

Stadly added a commit to Stadly/phpunit that referenced this issue Jan 24, 2019

Add regression test for issue sebastianbergmann#3240.
This proves that the bug reported in sebastianbergmann#3240 is also fixed in scope of this PR.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.