8000 [11.x] Fix missing `return $this` for `assertOnlyJsonValidationErrors` by LeTamanoir · Pull Request #55099 · laravel/framework · GitHub
[go: up one dir, main page]

Skip to content

[11.x] Fix missing return $this for assertOnlyJsonValidationErrors #55099

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

Conversation

LeTamanoir
Copy link
Contributor

The assertOnlyJsonValidationErrors does not return $this even though it is type hinted to return $this.

/**
* Assert that the response has the given JSON validation errors but does not have any other JSON validation errors.
*
* @param string|array $errors
* @param string $responseKey
* @return $this
*/
public function assertOnlyJsonValidationErrors($errors, $responseKey = 'errors')
{
$this->assertJsonValidationErrors($errors, $responseKey);
$jsonErrors = Arr::get($this->json(), $responseKey) ?? [];
$expectedErrorKeys = collect($errors)->map(fn ($value, $key) => is_int($key) ? $value : $key)->all();
$unexpectedErrorKeys = Arr::except($jsonErrors, $expectedErrorKeys);
PHPUnit::withResponse($this)->assertTrue(count($unexpectedErrorKeys) === 0, 'Response has unexpected validation errors: '.collect($unexpectedErrorKeys)->keys()->map(fn ($key) => "'{$key}'")->join(', '));
}

@taylorotwell taylorotwell merged commit b8a8f83 into laravel:11.x Mar 22, 2025
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0