From 222a50b54d34e0628515c7b855115c976a844fb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Falc=C3=B3n?= Date: Fri, 1 Jan 2021 12:56:19 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Capture=20all=20exceptions=20and?= =?UTF-8?q?=20throw=20them=20(#4)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/PendingTrigger.php | 2 +- tests/ValidationTaskTest.php | 8 ++++++++ tests/stub/WrongValidationTask.php | 25 +++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 tests/stub/WrongValidationTask.php diff --git a/src/PendingTrigger.php b/src/PendingTrigger.php index b85b3f2..a92c140 100644 --- a/src/PendingTrigger.php +++ b/src/PendingTrigger.php @@ -35,7 +35,7 @@ public function withValid(array $data): self } $this->task->validated($validator->validated()); - } catch (\BadMethodCallException $exception) { + } catch (\Exception $exception) { $this->error = true; throw $exception; } diff --git a/tests/ValidationTaskTest.php b/tests/ValidationTaskTest.php index 5a3a6ab..d3a4332 100644 --- a/tests/ValidationTaskTest.php +++ b/tests/ValidationTaskTest.php @@ -8,6 +8,7 @@ use Orchestra\Testbench\TestCase; use VictorFalcon\LaravelTask\ServiceProvider; use VictorFalcon\LaravelTask\Tests\stub\ValidationTask; +use VictorFalcon\LaravelTask\Tests\stub\WrongValidationTask; class ValidationTaskTest extends TestCase { @@ -33,4 +34,11 @@ public function testTaskWithValidationTriggerErrors() ]) ->result(); } + + public function testItThrowsAnErrorWhenThereAreSomeError(): void + { + $this->expectExceptionMessage('Method Illuminate\Validation\Validator::validateInvalidaValidationRule does not exist.'); + + WrongValidationTask::trigger()->withValid(['name' => 'Jhon Doe']); + } } diff --git a/tests/stub/WrongValidationTask.php b/tests/stub/WrongValidationTask.php new file mode 100644 index 0000000..baf9398 --- /dev/null +++ b/tests/stub/WrongValidationTask.php @@ -0,0 +1,25 @@ + 'invalida_validation_rule', + ]; + } + + public function handle(): array + { + return $this->data ?? []; + } +}