public function testGetDataSourceIterator()
 {
     $fields = array('title' => '[title]');
     $firstResult = 10;
     $maxResults = 25;
     $data = array(array('id' => 42, 'title' => 'Super!'), array('id' => 24, 'title' => 'Foo'));
     $results = new \PropelCollection();
     $results->setData($data);
     // configure the query mock
     $query = $this->getMock('Sonata\\AdminBundle\\Datagrid\\ProxyQueryInterface');
     $query->expects($this->once())->method('setFirstResult')->with($this->equalTo($firstResult));
     $query->expects($this->once())->method('setMaxResults')->with($this->equalTo($maxResults));
     $query->expects($this->once())->method('execute')->will($this->returnValue($results));
     // configure the datagrid mock
     $datagrid = $this->getMockBuilder('Sonata\\PropelAdminBundle\\Datagrid\\Datagrid')->disableOriginalConstructor()->setMethods(array('buildPager', 'getQuery'))->getMock();
     $datagrid->expects($this->once())->method('buildPager');
     $datagrid->expects($this->once())->method('getQuery')->will($this->returnValue($query));
     // create the manager
     $manager = new ModelManager();
     // and finally test it!
     $collectionIterator = $manager->getDataSourceIterator($datagrid, $fields, $firstResult, $maxResults);
     $this->assertInstanceOf('\\Exporter\\Source\\PropelCollectionSourceIterator', $collectionIterator);
     $this->assertSame(array(array('title' => 'Super!'), array('title' => 'Foo')), iterator_to_array($collectionIterator));
 }
 public function testIsEven()
 {
     $col = new PropelCollection();
     $this->assertTrue($col->isEven(), 'isEven() returns true on an empty collection');
     $data = array('bar1', 'bar2', 'bar3');
     $col = new PropelCollection();
     $col->setData($data);
     foreach ($col as $key => $value) {
         $this->assertEquals(!(bool) ($key % 2), $col->isEven(), 'isEven() returns true only when the key is even');
     }
 }
 public function deserializeCollection(VisitorInterface $visitor, $data, Type $type, Context $context)
 {
     $collection = new \PropelCollection();
     $collection->setData($visitor->visitArray($data, $type, $context));
     return $collection;
 }