Skip to content

Commit

Permalink
Ensure validation starts again when action is run multiple times
Browse files Browse the repository at this point in the history
See #26
  • Loading branch information
lorisleiva committed Oct 31, 2019
1 parent 57c7e7f commit dc8d1ac
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Concerns/ResolvesValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ public function getValidationErrors()

protected function resolveValidation()
{
$this->validator = null;

if (! $this->passesValidation()) {
$this->failedValidation();
}
Expand Down
23 changes: 23 additions & 0 deletions tests/ResolvesValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,27 @@ public function handle() {
$this->assertEquals(['operation' => 'valid'], $result['first']);
$this->assertNull($result['second']);
}

/** @test */
public function validation_should_restart_when_running_again()
{
$action = new class extends Action {
public function rules() {
return ['name' => 'required'];
}
public function handle() {
return $this->validated();
}
};

$this->assertEquals(
['name' => 'Alice'],
$action->run(['name' => 'Alice'])
);

$this->assertEquals(
['name' => 'Bob'],
$action->run(['name' => 'Bob'])
);
}
}

0 comments on commit dc8d1ac

Please sign in to comment.