Skip to content

Commit

Permalink
getErrors()メソッドを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
k-holy committed Oct 24, 2016
1 parent dc78e6d commit cd4adce
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ public function getResult()
return $this->result;
}

/**
* 検証結果からエラーのリストを返します。
*
* @return array
*/
public function getErrors()
{
return $this->result->getErrors();
}

/**
* 検証結果からエラーをクリアします。
*/
Expand Down
12 changes: 12 additions & 0 deletions tests/Volcanus/Validation/Test/ContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ public function testSetErrorAndUnsetError()
$this->assertTrue($validation->isValid());
}

public function testSetErrorAndGetErrors()
{
$validation = new Context();
$validation->setError('id1', 'notFound');
$validation->setError('id2', 'notFound');
$errors = $validation->getErrors();
$this->assertArrayHasKey('id1', $errors);
$this->assertInstanceOf('\Volcanus\Validation\Error', $errors['id1']);
$this->assertArrayHasKey('id2', $errors);
$this->assertInstanceOf('\Volcanus\Validation\Error', $errors['id2']);
}

public function testSetErrorAndClearErrors()
{
$validation = new Context();
Expand Down

0 comments on commit cd4adce

Please sign in to comment.