コード例 #1
0
 protected function setUp()
 {
     $entities = array(new EntityCategory(1, 'category name 1'), new EntityCategory(2, 'category name 2'));
     $configuration = $this->getMock('Doctrine\\ORM\\Configuration');
     $objectManager = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $objectManager->expects($this->any())->method('getConfiguration')->will($this->returnValue($configuration));
     $objectManager->expects($this->any())->method('getExpressionBuilder')->will($this->returnValue(new Expr()));
     $query = $this->getMock('Doctrine\\ORM\\AbstractQuery', array('execute', '_doExecute', 'getSql', 'setFirstResult', 'setMaxResults'), array($objectManager));
     $query->expects($this->any())->method('execute')->will($this->returnValue($entities));
     $query->expects($this->any())->method('setFirstResult')->will($this->returnValue($query));
     $query->expects($this->any())->method('setMaxResults')->will($this->returnValue($query));
     $objectManager->expects($this->any())->method('createQuery')->withAnyParameters()->will($this->returnValue($query));
     $queryBuilder = new QueryBuilder($objectManager);
     $entityClass = 'FSi\\Component\\DataGrid\\Tests\\Fixtures\\EntityCategory';
     $classMetadata = new ClassMetadata('FSi\\Component\\DataGrid\\Tests\\Fixtures\\EntityCategory');
     $classMetadata->identifier = array('id');
     $classMetadata->fieldMappings = array('id' => array('fieldName' => 'id', 'type' => 'integer'));
     $classMetadata->reflFields = array('id' => new \ReflectionProperty($entityClass, 'id'));
     $repository = $this->getMock('Doctrine\\ORM\\EntityRepository', array(), array($objectManager, $classMetadata));
     $repository->expects($this->any())->method('createQueryBuilder')->withAnyParameters()->will($this->returnValue($queryBuilder));
     $repository->expects($this->any())->method('findAll')->will($this->returnValue($entities));
     $objectManager->expects($this->any())->method('getClassMetadata')->withAnyParameters()->will($this->returnValue($classMetadata));
     $objectManager->expects($this->any())->method('getRepository')->will($this->returnValue($repository));
     $objectManager->expects($this->any())->method('contains')->will($this->returnValue(true));
     $managerRegistry = $this->getMock('Doctrine\\Common\\Persistence\\ManagerRegistry');
     $managerRegistry->expects($this->any())->method('getManagerForClass')->will($this->returnValue($objectManager));
     $managerRegistry->expects($this->any())->method('getManagers')->will($this->returnValue(array()));
     $resolvedTypeFactory = new ResolvedFormTypeFactory();
     $formRegistry = new FormRegistry(array(new CoreExtension(), new DoctrineOrmExtension($managerRegistry), new CsrfExtension(new CsrfTokenManager())), $resolvedTypeFactory);
     $formFactory = new FormFactory($formRegistry, $resolvedTypeFactory);
     $this->dataGrid = $this->getMock('FSi\\Component\\DataGrid\\DataGridInterface');
     $this->dataGrid->expects($this->any())->method('getName')->will($this->returnValue('grid'));
     $this->extension = new FormExtension($formFactory);
 }
コード例 #2
0
 public function testSetDataForArray()
 {
     $gridData = array(array('one'), array('two'), array('three'), array('four'), array('bazinga!'), array('five'));
     $this->datagrid->setData($gridData);
     $view = $this->datagrid->createView();
     $keys = array();
     foreach ($view as $row) {
         $keys[] = $row->getIndex();
     }
     $this->assertEquals(array_keys($gridData), $keys);
 }
コード例 #3
0
 /**
  * {@inheritdoc}
  */
 public function getData()
 {
     return array('datagrid_view' => $this->dataGrid->createView(), 'datasource_view' => $this->dataSource->createView(), 'element' => $this->element);
 }