From 70b4729d07fa5cdfe01e1dd9ac2595cb9fb3df7d Mon Sep 17 00:00:00 2001 From: Nikolay Novikov Date: Thu, 19 Sep 2024 19:11:29 +0300 Subject: [PATCH] patch --- src/Tests/ValidationTrait.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/Tests/ValidationTrait.php b/src/Tests/ValidationTrait.php index bf7d659..715efae 100644 --- a/src/Tests/ValidationTrait.php +++ b/src/Tests/ValidationTrait.php @@ -112,4 +112,26 @@ protected function assertDeleteValidationFailed(\Illuminate\Database\Eloquent\Mo } } } + + /** + * Asserts that custom action gets validation failure + * + * @param callable $closure + * @param mixed $message + * @return void + */ + protected function assertCustomValidationFailed(callable $closure, $message = true): void + { + try { + $closure(); + $this->assertFalse(true); + } catch (\Illuminate\Validation\ValidationException $e) { + foreach ($e->validator->errors()->all() as $error) { + $this->assertStringNotContainsString('services/', $error); + if ($message !== true) { + $this->assertEquals($message, $error); + } + } + } + } }