public function diff(ContactCollection $collection)
 {
     $array = $collection->read();
     $data = $this->read();
     $result = array_diff_key($data, $array);
     return new ContactCollection($result);
 }
 /**
  * `create()` function should add Contact to end of stack. If array is given
  * it should be internally coonverted to Contact object
  */
 public function testCreateFromArray()
 {
     $contact1 = array('FirstName' => 'FirstName1', 'Email' => '*****@*****.**');
     $contact2 = array('FirstName' => 'FirstName2', 'Email' => '*****@*****.**');
     $c = new ContactCollection(array($contact1, $contact2));
     $expected = $c->count();
     $this->assertEquals($expected, 2);
 }
 /**
  * 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 push(ContactCollection $collection)
 {
     $isdk = $this->getIsdk();
     $count = $collection->count();
     $result = array('skip' => new ContactCollection(), 'create' => new ContactCollection(), 'update' => new ContactCollection(), 'fail' => new ContactCollection());
     $contacts = $collection->read();
     switch ($count) {
         case 0:
             return $result;
             break;
             /**
              * If Collection has 1 contact we don't want to pull all contacts from
              * remote API.
              */
         /**
          * If Collection has 1 contact we don't want to pull all contacts from
          * remote API.
          */
         case 1:
             $contact = reset($contacts);
             $id = $contact->getId();
             if ($id) {
                 // Contact Id is set. Most likely this is update
                 $c = $this->updateContact($contact);
             } else {
                 // Contact ID not set. Most likely this is new contact
                 $c = $this->createContact($contact);
             }
             if ($c->isCreated()) {
                 $result['create']->create($c);
             } elseif ($c->isUpdated()) {
                 $result['update']->create($c);
             } elseif ($c->isSkipped()) {
                 $result['skip']->create($c);
             } elseif ($c->isFailed()) {
                 $result['fail']->create($c);
             }
             break;
         default:
             foreach ($contacts as $contact) {
                 $id = $contact->getId();
                 if ($id) {
                     // Contact Id is set. Most likely this is update
                     $c = $this->updateContact($contact);
                 } else {
                     // Contact ID not set. Most likely this is new contact
                     $c = $this->createContact($contact);
                 }
                 if ($c->isCreated()) {
                     $result['create']->create($c);
                 } elseif ($c->isUpdated()) {
                     $result['update']->create($c);
                 } elseif ($c->isSkipped()) {
                     $result['skip']->create($c);
                 } elseif ($c->isFailed()) {
                     $result['fail']->create($c);
                 }
             }
     }
     return $result;
 }
 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());
 }