public function testImplicitFetch()
 {
     // Test setters/getters
     $response = $this->createEmptyResponseMock();
     $cursor = new Cursor($response, $this->objectPrototype);
     $this->assertFalse(Cursor::getDefaultUseImplicitFetch());
     $this->assertFalse($cursor->getUseImplicitFetch());
     $cursor->setUseImplicitFetch(true);
     $this->assertTrue($cursor->getUseImplicitFetch());
     Cursor::setDefaultUseImplicitFetch(true);
     $response = $this->createEmptyResponseMock();
     $cursor = new Cursor($response, $this->objectPrototype);
     $this->assertTrue(Cursor::getDefaultUseImplicitFetch());
     $this->assertTrue($cursor->getUseImplicitFetch());
     // Test ordered iteration
     // f() lower interval * min repetition > upper interval
     // Min repetition > upper interval / lower interval -> f(x): x > 5 / 2 -> 3
     $response = $this->createResponseChainMock(3);
     $cursor = new Cursor($response, $this->objectPrototype);
     while ($cursor->valid()) {
         $cursor->next();
     }
     // Min upper boundary = upper interval + 1 = 5 + 1 = 6
     $this->assertGreaterThanOrEqual(6, $cursor->count());
     // Test rervese iteration
     // same f()
     $response = $this->createResponseChainMock(3);
     $cursor = new Cursor($response, $this->objectPrototype);
     $count = 0;
     while ($cursor->valid()) {
         $cursor->prev();
     }
     $this->assertGreaterThanOrEqual(6, $cursor->count());
     // Force the array out of boundaries
     $response = $this->createResponseChainMock(1);
     $cursor = new Cursor($response, $this->objectPrototype);
     $cursor->setUseImplicitFetch(false);
     $cursor->prev();
     // Restore static behaviour
     Cursor::setDefaultUseImplicitFetch(false);
 }
Exemplo n.º 2
0
 public function testCountable()
 {
     $objects = array();
     $account = new AdAccount();
     $count = rand(0, 100);
     for ($i = 0; $i < $count; $i++) {
         $objects[] = clone $account;
     }
     $cursor = new Cursor($objects, $this->response);
     $this->assertTrue($cursor instanceof \Countable);
     $this->assertEquals($cursor->count(), $count);
 }