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 testAddDuplicateNameException() { $tmpNames = array(); $this->datagridMapper->getAdmin()->expects($this->exactly(2))->method('hasFilterFieldDescription')->will($this->returnCallback(function ($name) use(&$tmpNames) { if (isset($tmpNames[$name])) { return true; } $tmpNames[$name] = $name; return false; })); try { $this->datagridMapper->add('fooName'); $this->datagridMapper->add('fooName'); } catch (\RuntimeException $e) { $this->assertContains('Duplicate field name "fooName" in datagrid mapper. Names should be unique.', $e->getMessage()); return; } $this->fail('Failed asserting that exception of type "\\RuntimeException" is thrown.'); }
/** * {@inheritdoc} */ public function configureDatagridFilters(DatagridMapper $filter) { $this->eventDispatcher->dispatch('sonata.admin.event.configure.datagrid', new ConfigureEvent($filter->getAdmin(), $filter, ConfigureEvent::TYPE_DATAGRID)); }