Skip to content
This repository was archived by the owner on Feb 26, 2018. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 837e799

Browse files
committedJun 22, 2016
Update to return array instead of collection
1 parent fe848dc commit 837e799

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed
 

‎src/AdamWathan/Form/FormBuilder.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,11 @@ public function hasError($name)
207207

208208
public function getErrors()
209209
{
210-
return $this->errorStore->getErrors();
210+
if(! $this->hasErrors()){
211+
return null;
212+
}
213+
214+
return $this->errorStore->getErrors()->all();
211215
}
212216

213217
public function getError($name, $format = null)

‎tests/FormBuilderTest.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,22 @@ public function testCanRetrieveErrorMessages()
217217
{
218218
$errors = new MessageBag(['foo.bar' => 'Some error']);
219219
$errorStore = Mockery::mock('AdamWathan\Form\ErrorStore\ErrorStoreInterface');
220+
$errorStore->shouldReceive('hasErrors')->andReturn(true);
220221
$errorStore->shouldReceive('getErrors')->andReturn($errors);
221222

222223
$this->form->setErrorStore($errorStore);
223224

224-
$expected = $errors;
225+
$expected = $errors->all();
226+
$result = $this->form->getErrors();
227+
$this->assertEquals($expected, $result);
228+
229+
$errorStore = Mockery::mock('AdamWathan\Form\ErrorStore\ErrorStoreInterface');
230+
$errorStore->shouldReceive('hasErrors')->andReturn(false);
231+
$errorStore->shouldReceive('getErrors')->andReturn(null);
232+
233+
$this->form->setErrorStore($errorStore);
234+
235+
$expected = null;
225236
$result = $this->form->getErrors();
226237
$this->assertEquals($expected, $result);
227238
}

0 commit comments

Comments
 (0)
This repository has been archived.