public function testPullPaged()
{
$messages = ['receivedMessages' => [['foo' => 'bar'], ['foo' => 'bat']], 'nextPageToken' => 'foo'];
$this->connection->pull(Argument::that(function ($args) {
if ($args['foo'] !== 'bar') {
return false;
}
if ($args['returnImmediately'] !== true) {
return false;
}
if ($args['maxMessages'] !== 2) {
return false;
}
if (!in_array($args['pageToken'], [null, 'foo'])) {
return false;
}
return true;
}))->willReturn($messages)->shouldBeCalledTimes(3);
$subscription = new Subscription($this->connection->reveal(), 'subscription-name', 'topic-name', 'project-id');
$result = $subscription->pull(['foo' => 'bar', 'returnImmediately' => true, 'maxMessages' => 2]);
$this->assertInstanceOf(Generator::class, $result);
// enumerate the iterator and kill after it loops twice.
$arr = [];
$i = 0;
foreach ($result as $message) {
$i++;
$arr[] = $message;
if ($i == 6) {
break;
}
}
$this->assertEquals(6, count($arr));
}