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

assertJsonStringEqualsJsonString() considers objects with sequential numeric keys equal to be arrays #4584

Closed
lpd-au opened this issue Jan 14, 2021 · 0 comments
Labels
type/bug Something is broken

Comments

@lpd-au
Copy link

lpd-au commented Jan 14, 2021

Q A
PHPUnit version 9.5.0
PHP version 7.4.14
Installation Method Composer

Summary

When a PHP array with sequentially increasing numeric keys is encoded twice, once with JSON_FORCE_OBJECT and once without JSON_FORCE_OBJECT, assertJsonStringEqualsJsonString considers both outputs to be equal.

How to reproduce

$a = '[{}]';
$b = '{"0": {}}';
$this->assertJsonStringEqualsJsonString($a, $b);
$this->assertEquals(json_decode($a), json_decode($b));
$this->assertJsonStringEqualsJsonString('[]', '{}');
$this->assertJsonStringEqualsJsonString('{}', '[]');

Current behavior

The first test passes and the remaining three fail.

Expected behavior

All tests fail because, when decoded,

array(1) {
  [0]=>
  object(stdClass)#1 (0) {
  }
}

does not equal

object(stdClass)#2 (1) {
  ["0"]=>
  object(stdClass)#1 (0) {
  }
}
@lpd-au lpd-au added the type/bug Something is broken label Jan 14, 2021
@sebastianbergmann sebastianbergmann changed the title assertJsonStringEqualsJsonString considers objects with sequential numeric keys equal to arrays assertJsonStringEqualsJsonString() considers objects with sequential numeric keys equal to arrays Sep 7, 2024
@sebastianbergmann sebastianbergmann changed the title assertJsonStringEqualsJsonString() considers objects with sequential numeric keys equal to arrays assertJsonStringEqualsJsonString() considers objects with sequential numeric keys equal to be arrays Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something is broken
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants