示例#1
0
 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);
 }
示例#2
0
 public function testFindWithoutLimit()
 {
     $queryConfig = clone $this->queryConfig;
     $queryConfig->setLimit(0);
     $result = $this->dataProvider->find($this->queryBuilder, $queryConfig);
     $this->assertInstanceOf('EMC\\TableBundle\\Provider\\QueryResultInterface', $result);
     $this->assertEquals(0, $result->getCount());
 }