本文整理汇总了PHP中PropelCollection::setData方法的典型用法代码示例。如果您正苦于以下问题:PHP PropelCollection::setData方法的具体用法?PHP PropelCollection::setData怎么用?PHP PropelCollection::setData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PropelCollection
的用法示例。
在下文中一共展示了PropelCollection::setData方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testGetDataSourceIterator
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));
}
示例2: testIsEven
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');
}
}
示例3: deserializeCollection
public function deserializeCollection(VisitorInterface $visitor, $data, Type $type, Context $context)
{
$collection = new \PropelCollection();
$collection->setData($visitor->visitArray($data, $type, $context));
return $collection;
}