/**
  * `count()` is for calculating total amount of contacts in collection
  */
 public function testCount()
 {
     $c = new ContactCollection();
     $expected = $c->count();
     $this->assertEquals(0, $expected);
     $contact1 = array('FirstName' => 'FirstName1', 'Email' => '*****@*****.**');
     $contact2 = array('FirstName' => 'FirstName2', 'Email' => '*****@*****.**');
     $c->create($contact1);
     $c->create($contact2);
     $expected = $c->count();
     $this->assertEquals(2, $expected);
 }
 public function pull()
 {
     $allContacts = new ContactCollection();
     $isdk = $this->getIsdk();
     $fields = $this->getConfigFields();
     if (!in_array('Groups', array_values($fields))) {
         $fields[] = 'Groups';
     }
     if (!in_array('LastUpdated', array_values($fields))) {
         $fields[] = 'LastUpdated';
     }
     if (!in_array('Id', array_values($fields))) {
         $fields[] = 'Id';
     }
     $validTags = $this->getConfigTags();
     $limit = 1000;
     $page = 0;
     while (true) {
         $results = $isdk->dsQuery('Contact', $limit, $page, array('Id' => '%'), $fields);
         if (is_string($results)) {
             throw new SyncException($results);
         } else {
             if (is_array($results)) {
                 foreach ($results as $r) {
                     $tags = array();
                     if (!empty($r['Groups'])) {
                         $tags = array_intersect(explode(',', $r['Groups']), $validTags);
                         unset($r['Groups']);
                     }
                     $c = new Contact($r);
                     $c->setTags($tags);
                     $allContacts->create($c);
                 }
             }
         }
         if (count($results) < $limit) {
             break;
         }
         $page++;
     }
     return $allContacts;
 }
 /**
  * When we push one contact we don't need to load all contacts from IS.
  * This is handy when you know exactly that contact is new and didn't
  * present remotely.
  */
 public function testPushOneContactUpdate()
 {
     $contact = new Contact(array('Id' => 1, 'Email' => '*****@*****.**', 'FirstName' => 'FirstName1'));
     $collection = new ContactCollection();
     $collection->create($contact);
     $i = $this->getMockBuilder('\\Wildsurfer\\Infusionsoft\\Sync')->disableOriginalConstructor()->setMethods(array('updateContact'))->getMock();
     $i->expects($this->once())->method('updateContact')->will($this->returnValue($contact));
     $i->expects($this->never())->method('createContact');
     $isdk = $this->getMockedIsdk();
     $isdk->expects($this->never())->method('dsQuery');
     $i->setIsdk($isdk);
     $i->push($collection);
 }
 public function testContactFieldOwnerID()
 {
     $data = array('OwnerID' => 1);
     $config = $this->testConfig;
     $config['fields'] = array_keys($data);
     $i = new Sync($config);
     $isdk = $i->getIsdk();
     $contact = new Contact($data);
     $collection = new ContactCollection();
     $collection->create($contact);
     $c = $i->push($collection);
     $read = $c['create']->read();
     $readData = reset($read);
     $expected = $isdk->loadCon($readData->getId(), $i->getConfigFields());
     foreach ($data as $k => $v) {
         $fields = $contact->getData();
         $this->assertEquals($expected[$k], $fields[$k]);
     }
     $isdk->dsDelete('Contact', $readData->getId());
 }