Browse Source

Specify the error message

Sergey Polischuk 11 years ago
parent
commit
c3725b43b4
2 changed files with 20 additions and 0 deletions
  1. 2 0
      Datagrid/DatagridMapper.php
  2. 18 0
      Tests/Datagrid/DatagridMapperTest.php

+ 2 - 0
Datagrid/DatagridMapper.php

@@ -67,6 +67,8 @@ class DatagridMapper extends BaseMapper
                 $name,
                 $filterOptions
             );
+        } elseif (is_string($name) && $this->admin->hasFilterFieldDescription($name)) {
+            throw new \RuntimeException(sprintf('The field "%s" is already defined', $name));
         } else {
             throw new \RuntimeException('invalid state');
         }

+ 18 - 0
Tests/Datagrid/DatagridMapperTest.php

@@ -188,6 +188,24 @@ class DatagridMapperTest extends \PHPUnit_Framework_TestCase
         $this->fail('Failed asserting that exception of type "\RuntimeException" is thrown.');
     }
 
+    public function testAddException2()
+    {
+        try {
+            $this->datagridMapper->getAdmin()
+                ->expects($this->any())
+                ->method('hasFilterFieldDescription')
+                ->will($this->returnValue(true))
+            ;
+            $this->datagridMapper->add('field');
+        } catch (\RuntimeException $e) {
+            $this->assertContains('The field "field" is already defined', $e->getMessage());
+
+            return;
+        }
+
+        $this->fail('Failed asserting that exception of type "\RuntimeException" is thrown.');
+    }
+
     public function testReorder()
     {
         $fieldDescription1 = $this->getFieldDescriptionMock('fooName1', 'fooLabel1');