Skip to content

Commit

Permalink
Add an example test.
Browse files Browse the repository at this point in the history
This test will error without the `(array)` cast in the previous commit.
  • Loading branch information
beporter committed Jan 28, 2016
1 parent fdf743a commit 44d74ec
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion tests/TestCase/View/Form/FormContextTest.php
Expand Up @@ -196,9 +196,21 @@ public function testError()
$this->assertEquals(['The provided value is invalid'], $context->error('email'));
$this->assertEquals(['The provided value is invalid'], $context->error('name'));
$this->assertEquals(['The provided value is invalid'], $context->error('pass.password'));

$this->assertEquals([], $context->error('Alias.name'));
$this->assertEquals([], $context->error('nope.nope'));

$mock = $this->getMock('Cake\Validation\Validator', ['errors']);
$mock->expects($this->once())
->method('errors')
->willReturn(['key' => 'should be an array, not a string']);
$form->validator($mock);
$form->validate([]);
$context = new FormContext($this->request, ['entity' => $form]);
$this->assertEquals(
['should be an array, not a string'],
$context->error('key'),
'This test should not produce a PHP warning from array_values().'
);
}

/**
Expand Down

0 comments on commit 44d74ec

Please sign in to comment.