Skip to content

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

Merged
taylorotwell merged 1 commit into
laravel:11.xfrom
LeTamanoir:fix-assert-only-json-validation-errors-return-missing
Mar 22, 2025
Merged

[11.x] Fix missing return $this for assertOnlyJsonValidationErrors#55099
taylorotwell merged 1 commit into
laravel:11.xfrom
LeTamanoir:fix-assert-only-json-validation-errors-return-missing

Conversation

@LeTamanoir
Copy link
Copy Markdown
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
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