public function setUp() { $this->entityManagerMock = $this->getMock('Doctrine\\Common\\Persistence\\ObjectManager'); $this->eventDispatcherMock = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface'); $this->columnFactoryMock = $this->getMock('EMC\\TableBundle\\Table\\Column\\ColumnFactoryInterface'); $columnTypeIdMock = $this->getMock('EMC\\TableBundle\\Table\\Column\\Type\\ColumnTypeInterface'); $columnTypeNameMock = $this->getMock('EMC\\TableBundle\\Table\\Column\\Type\\ColumnTypeInterface'); $columnTypeTestMock = $this->getMock('EMC\\TableBundle\\Table\\Column\\Type\\ColumnTypeInterface'); $that = $this; $this->columnFactoryMock->expects($this->any())->method('create')->with($this->logicalOr($this->equalTo('id'), $this->equalTo('name'), $this->equalTo('test')))->will($this->returnCallback(function ($name, $type, $options) use($that, $columnTypeIdMock, $columnTypeNameMock, $columnTypeTestMock) { $options['name'] = $name; switch ($name) { case 'id': return new ColumnBuilder($columnTypeIdMock, $that->getResolvedOptions(array_merge($options, array('params' => array('id'), 'allow_sort' => false)))); case 'name': return new ColumnBuilder($columnTypeNameMock, $that->getResolvedOptions(array_merge($options, array('params' => array('name'), 'allow_sort' => array('name', 'id'), 'allow_filter' => true)))); default: return new ColumnBuilder($columnTypeTestMock, $that->getResolvedOptions(array_merge($options, array('params' => array('w' => 'x'), 'allow_sort' => array('y'), 'allow_filter' => array('z'))))); } })); $this->queryResult = new QueryResult(self::$rows, count(self::$rows)); $this->dataProvider = $this->getMock('EMC\\TableBundle\\Provider\\DataProviderInterface'); $this->dataProvider->expects($this->any())->method('find')->will($this->returnValue($this->queryResult)); $options = array('data_provider' => $this->dataProvider); $queryBuilder = $this->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->getMock(); $this->fooType = new Type\FooType($queryBuilder); $optionsResolver = new OptionsResolver(); $this->fooType->setDefaultOptions($optionsResolver, $this->defaultOptions); $this->resolvedOptions = $optionsResolver->resolve($options); $this->resolvedOptions['_tid'] = 'test'; $this->resolvedOptions['_passed_options'] = array(); $this->resolvedOptions['_query'] = array('page' => 1, 'sort' => 0, 'limit' => 10, 'filter' => null); $this->builder = new TableBuilder($this->entityManagerMock, $this->eventDispatcherMock, $this->columnFactoryMock, $this->fooType, $this->defaultColumnOptions, null, $this->resolvedOptions); }
/** * {@inheritdoc} */ public function add($name, $type, array $options = array()) { if (isset($this->columns[$name])) { throw new \InvalidArgumentException('Column name "' . $name . '" already exists.'); } $this->columns[$name] = $this->factory->create($name, $type, $options, $this->defaultColumnOptions)->getColumn(); return $this; }
public function testCreate() { $column = $this->factory->create('foo', 'bar', array(), $this->defaultColumnOptions); $options = $column->getColumn()->getOptions(); $this->assertArrayHasKey('_passed_options', $options); }