Browse Source

Add an example test.

This test will error without the `(array)` cast in the previous commit.
Brian Porter 10 years ago
parent
commit
44d74ec030
1 changed files with 13 additions and 1 deletions
  1. 13 1
      tests/TestCase/View/Form/FormContextTest.php

+ 13 - 1
tests/TestCase/View/Form/FormContextTest.php

@@ -196,9 +196,21 @@ class FormContextTest extends TestCase
         $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().'
+        );
     }
 
     /**