Browse Source

Improve error message.

ADmad 8 years ago
parent
commit
89250d1dd2
2 changed files with 6 additions and 4 deletions
  1. 5 3
      src/View/Form/ContextFactory.php
  2. 1 1
      tests/TestCase/View/Helper/FormHelperTest.php

+ 5 - 3
src/View/Form/ContextFactory.php

@@ -141,9 +141,11 @@ class ContextFactory
             $context = new NullContext($request, $data);
         }
         if (!($context instanceof ContextInterface)) {
-            throw new RuntimeException(
-                'Context objects must implement Cake\View\Form\ContextInterface'
-            );
+            throw new RuntimeException(sprintf(
+                'Context providers must return object implementing %s. Got "%s" instead.',
+                'Cake\View\Form\ContextInterface',
+                is_object($context) ? get_class($context) : gettype($context)
+            ));
         }
 
         return $context;

+ 1 - 1
tests/TestCase/View/Helper/FormHelperTest.php

@@ -386,7 +386,7 @@ class FormHelperTest extends TestCase
      * Test adding an invalid context class.
      *
      * @expectedException \RuntimeException
-     * @expectedExceptionMessage Context objects must implement Cake\View\Form\ContextInterface
+     * @expectedExceptionMessage Context providers must return object implementing Cake\View\Form\ContextInterface. Got "stdClass" instead.
      * @return void
      */
     public function testAddContextProviderInvalid()