public function testGetters()
 {
     $response = $this->createResponseChainMock(1);
     $cursor = new Cursor($response, $this->objectPrototype);
     $this->assertTrue($response === $cursor->getResponse());
     $this->assertTrue($response === $cursor->getLastResponse());
     $this->assertNull($cursor->getAfter());
     $this->assertNull($cursor->getBefore());
 }
 /**
  * Transform a FacebookAds\Cursor object into a Collection.
  *
  * @param Cursor $response
  *
  * @return Collection
  */
 public function response(Cursor $response)
 {
     $data = new Collection();
     while ($response->current()) {
         $data->push($response->current()->getData());
         $response->next();
     }
     return $data;
 }
 public function testExportability()
 {
     $response = $this->createResponseChainMock(1);
     $cursor = new Cursor($response, $this->objectPrototype);
     $array_copy = $cursor->getArrayCopy();
     $this->assertTrue(is_array($array_copy));
     $this->assertEquals($cursor->getArrayCopy(), $cursor->getObjects());
     $this->assertEquals(count($array_copy), count($response->getContent()['data']));
     foreach ($array_copy as $object) {
         if (!$object instanceof AbstractObject) {
             $this->fail("Wrong instance in array copy");
         }
     }
     $cursor->fetchAfter();
     $cursor->fetchBefore();
     $index = $cursor->getIndexLeft();
     // Test in-memory order while exporting
     foreach ($cursor->getArrayCopy(true) as $key => $object) {
         if ($key < $index) {
             $this->fail("Wrong order in sorted array copy");
         }
     }
 }
예제 #4
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);
 }