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

[Bug]: toMatchArray - Field informed in the error message is the incorrect. #945

Closed
HENRIQUELOBO opened this issue Aug 31, 2023 · 2 comments

Comments

@HENRIQUELOBO
Copy link

HENRIQUELOBO commented Aug 31, 2023

What Happened

The “NAME” field informed in the error message is not incorrect, what is incorrect is the “AGE”.

test('check if value array matches the given subset', function () {
expect(['name' => 'lobo', 'age' => 10])->toMatchArray(['name' => 'lobo', 'age' => 0]);
});

Failed asserting that an array has a key 'name' with the value 'lobo'.
Failed asserting that 10 matches expected 0.
Expected :0
Actual :10

How to Reproduce

test('check if value array matches the given subset', function () {
expect(['name' => 'lobo', 'age' => 10])->toMatchArray(['name' => 'lobo', 'age' => 0]);
});

Sample Repository

No response

Pest Version

2.16.1

PHP Version

8.1

Operation System

Linux

Notes

No response

@HENRIQUELOBO HENRIQUELOBO changed the title [Bug]: toMatchArray - Field informed in the error message is the correct. [Bug]: toMatchArray - Field informed in the error message is the incorrect. Aug 31, 2023
@devajmeireles
Copy link
Member

Hey, @HENRIQUELOBO . Thanks for your report.

I was able to reproduce the behavior reported for you, but I don't think this is a bug or something related to that, I mean something that requires special attention. I will tag this as an enhancement to future Pest releases. Feel free to send us a PR with the enhancement in this part.

@drsdre
Copy link

drsdre commented Feb 25, 2025

Why is reporting the wrong field not an error? Just spend 2 hours trying to figure out on a large array what is not matching.

Getting a headache from the logic when $message from Assert::assertArrayHasKey($key, $valueAsArray, $message); is empty, it is considered as an error and $message is updated. It looks very hacky and wrong.

#1357 to fix this issue

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

No branches or pull requests

3 participants