/** * @test */ public function shouldReturnNextResultsWithGivenModel() { $data = array(array('id' => 1), array('id' => 2), array('id' => 3)); $contentRange = array('count' => 200, 'end' => 2, 'start' => 0); $response = $this->getMockBuilder('Uphold\\HttpClient\\Message\\Response')->disableOriginalConstructor()->getMock(); $response->expects($this->once())->method('getContent')->will($this->returnValue($data)); $response->expects($this->once())->method('getContentRange')->will($this->returnValue($contentRange)); $client = $this->getMockBuilder('Uphold\\UpholdClient')->disableOriginalConstructor()->setMethods(array('get'))->getMock(); $client->expects($this->once())->method('get')->with('/path', array(), array('range' => 'items=0-49'))->will($this->returnValue($response)); $pager = new Paginator($client, '/path'); $pager->setModel('Uphold\\Model\\Transaction'); $transactions = $pager->getNext(); foreach ($transactions as $transaction) { $this->assertInstanceOf('Uphold\\Model\\Transaction', $transaction); } }
/** * @test * * @expectedException Uphold\Exception\UpholdClientException * @expectedExceptionMessage foobar */ public function shouldThrownAnExceptionIfHttpCodeIsNot412Or416OnGetNext() { $client = $this->getMockBuilder('Uphold\\UpholdClient')->disableOriginalConstructor()->setMethods(array('get'))->getMock(); $client->expects($this->once())->method('get')->will($this->throwException(new UpholdClientException('foobar', 'qux', 500))); $pager = new Paginator($client, '/path'); $pager->getNext(); }