public function testGetPrevious() { $this->assertSame(null, $this->pager->getPrevious()); $object1 = new \stdClass(); $object1->foo = 'bar1'; $object2 = new \stdClass(); $object2->foo = 'bar2'; $object3 = new \stdClass(); $object3->foo = 'bar3'; $this->callMethod($this->pager, 'setNbResults', array(3)); $query = $this->getMock('Sonata\\AdminBundle\\Datagrid\\ProxyQueryInterface'); $query->expects($this->any())->method('setFirstResult')->will($this->returnValue($query)); $query->expects($this->any())->method('setMaxResults')->will($this->returnValue($query)); $id = 2; $query->expects($this->any())->method('execute')->will($this->returnCallback(function () use(&$id, $object1, $object2, $object3) { switch ($id) { case 0: return array($object1); case 1: return array($object2); case 2: return array($object3); } return; })); $this->pager->setQuery($query); $this->pager->setCursor(2); $this->assertSame($object3, $this->pager->getCurrent()); --$id; $this->assertSame($object2, $this->pager->getPrevious()); --$id; $this->assertSame($object1, $this->pager->getPrevious()); --$id; $this->assertSame(null, $this->pager->getPrevious()); }