Skip to content

Commit

Permalink
🐛 Capture all exceptions and throw them (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
victor-falcon authored Jan 1, 2021
1 parent d6a9ca0 commit 222a50b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/PendingTrigger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 8 additions & 0 deletions tests/ValidationTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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']);
}
}
25 changes: 25 additions & 0 deletions tests/stub/WrongValidationTask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace VictorFalcon\LaravelTask\Tests\stub;

use VictorFalcon\LaravelTask\Task;
use VictorFalcon\LaravelTask\Taskable;

class WrongValidationTask extends Task
{
use Taskable;

public function rules(): array
{
return [
'name' => 'invalida_validation_rule',
];
}

public function handle(): array
{
return $this->data ?? [];
}
}

0 comments on commit 222a50b

Please sign in to comment.