8000 misuse of `assertOnlyInvalid` could make tests passable · Issue #55510 · laravel/framework · GitHub
[go: up one dir, main page]

Skip to content

misuse of assertOnlyInvalid could make tests passable #55510

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

Closed
mondesirm opened this issue Apr 22, 2025 · 3 comments
Closed

misuse of assertOnlyInvalid could make tests passable #55510

mondesirm opened this issue Apr 22, 2025 · 3 comments

Comments

@mondesirm
Copy link

Laravel Version

12.9.1

PHP Version

8.4

Database Driver & Version

No response

Description

Context: In my tests, I wanted to replace all my assertInvalid assertions by assertOnlyInvalid then specify validation messages so I played around with parameters and tried to see if I could get away with doing assertOnlyInvalid('field', __('message')) instead of passing an array.

But I found the following a bit weird:

Image

I know this is not the proper way to use this method but that test still passes. In this example, the anomaly is pretty obvious (w/ typos and random letters) but let's say we're an innocent dev and tried the following:

Image

Obviously, there's no validation message with this key.
Since the test is passing and it looks okay to our eyes, it would pass by our radar.

Steps To Reproduce

  • Install any Starter Kit, I used the React one here.
  • Pick any test with assertSessionHasErrors and replace it with assertOnlyInvalid
  • Pass several arguments to it (do not use an array)
@mondesirm
Copy link
Author
mondesirm commented Apr 22, 2025

After more poking around, I also need to add this:

Image

  1. This fails like it should but only because we didn't pass a password key.
  2. It seems to totally and silently ignore keys and validation messages that don't exist.

Those 2 points are proved by the following:

Image

Image

Expected behavior: the fail should test if I'm passing nonsensical arguments.

Falling back to assertInvalid since it seems to behave correctly :

Image

Image

Image

Plus, the official VS Code extension's translation Intellisense doesn't support assertOnlyInvalid yet apparently.

@crynobone
Copy link
Member

Hey there, thanks for reporting this issue.

We'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue as one separate commit on the main/master branch and share the repository here?

Please make sure that you have the latest version of the Laravel installer in order to run this command. Please also make sure you have both Git & the GitHub CLI tool properly set up.

laravel new bug-report --github="--public"

Do not amend and create a separate commit with your custom changes. After you've posted the repository, we'll try to reproduce the issue.

Thanks!

@crynobone
Copy link
Member

Hey there,

We're closing this issue because it's inactive, already solved, old, or not relevant anymore. Feel free to open up a new issue if you're still experiencing this problem.

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

2 participants
0