Example #1
0
 public function testAddUnresolvedDependency()
 {
     $entityData = new EntityData('book', '12345', '<xml>...</xml>');
     $entityData->addDependency('author', '9876');
     // Tests if the dependency is existent
     foreach ($entityData->getUnresolvedDependencies() as $entityName => $dependency) {
         $this->assertEquals('author', $entityName);
         $this->assertEquals('9876', $dependency['data']);
         $this->assertNull($dependency['reference']);
     }
 }
 public function fetchEntities($entityName, $lastValue, $size)
 {
     $out = array();
     switch ($entityName) {
         case 'product':
             // Simple naive implementation comparing the entity id
             foreach ($this->remoteProducts as $remoteProduct) {
                 if (null != $size && count($out) == $size) {
                     return $out;
                 }
                 if ($remoteProduct->id > $lastValue || null == $lastValue) {
                     $ed = new EntityData($entityName, $remoteProduct->id);
                     // Indicate to the sync manager that we need the category dependency
                     $ed->addDependency('category', 'cat' . $remoteProduct->id);
                     $out[] = $ed;
                 }
             }
             break;
         case 'category':
             // Even more naive
             foreach ($this->remoteCategories as $remoteCat) {
                 if (null != $size && count($out) == $size) {
                     return $out;
                 }
                 $out[] = new EntityData($entityName, $remoteCat->name);
             }
             break;
     }
     return $out;
 }