3

Why is my test not failing? The actual and the expected json is completely different? What the fuck!?!

It says:

static::assertJson($expected, $actual);

right there.

Oh wait.

Nevermind.

`static::assertJson` only checks for any VALID json string that I always provided in with my own expectation m)

Use `assertJsonStringEqualsJsonString` instead.

What.

Who needs meaningful defaults.

(I would claim that `assertJson` should be defaulft for string equalness, and assertValidJson should be for any Json validation. But you are free to disagree.)

Comments
  • 2
    I would argue that `assertJson` is a bad name in the first place and should not be used at all. It's ambiguous and provides no information about what exactly it checks.
  • 0
    Whats your expected value then? Again the shit should give true or false back but if you put your other json as expected and it evaluates to true then this is rather the fault of a string evaluating to a boolean?
  • 1
    @noyb My entire mistake was falsely using `assertJson` over the correct `assertJsonStringEqualsJsonString` to begin with.

    There is no evaluation going on.

    `assertJson` will succeed if the first argument is a valid json (and as I pass in my $expected that is always a valid json it will always be true) and the second one is then merely the message phpunit would print if an error was to occur which was my actual JSON payload to test against.
  • 0
    assertJson should really be failing if the string isn't valid JSON
Add Comment