Browse Source

Zend_Service_Amazon: Fixes UTs + Fixes batchput of SimpleDb

SimpleDb::testPutAttributes fixed
SimpleDb::batchPutAttributes fixed to accept array of attribute values, and
allow to specify replace by associtative key.



git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@23271 44c647ce-9c0f-0410-b52a-842ac1e357ba
torio 15 years ago
parent
commit
92775c5940

+ 10 - 8
library/Zend/Service/Amazon/SimpleDb.php

@@ -231,17 +231,19 @@ class Zend_Service_Amazon_SimpleDb extends Zend_Service_Amazon_Abstract
             $params['Item.' . $itemIndex . '.ItemName'] = $name;
             $attributeIndex = 0;
             foreach ($attributes as $attribute) {
-                $params['Item.' . $itemIndex . '.Attribute.' . $attributeIndex . '.Name'] = $attribute->getName();
-                if (isset($replace[$itemIndex]) 
-                    && isset($replace[$itemIndex][$attributeIndex]) 
-                    && $replace[$itemIndex][$attributeIndex]
-                ) {
-                    $params['Item.' . $itemIndex . '.Attribute.' . $attributeIndex . '.Replace'] = 'true';
-                }
+                // attribute value cannot be array, so when several items are passed
+                // they are treated as separate values with the same attribute name
                 foreach($attribute->getValues() as $value) {
+                    $params['Item.' . $itemIndex . '.Attribute.' . $attributeIndex . '.Name'] = $attribute->getName();
                     $params['Item.' . $itemIndex . '.Attribute.' . $attributeIndex . '.Value'] = $value;
+                    if (isset($replace[$name]) 
+                        && isset($replace[$name][$attribute->getName()]) 
+                        && $replace[$name][$attribute->getName()]
+                    ) {
+                        $params['Item.' . $itemIndex . '.Attribute.' . $attributeIndex . '.Replace'] = 'true';
+                    }
+                    $attributeIndex++;
                 }
-                $attributeIndex++;
             }
             $itemIndex++;
         }

+ 5 - 1
tests/Zend/Service/Amazon/SimpleDb/OnlineTest.php

@@ -81,7 +81,7 @@ class Zend_Service_Amazon_SimpleDb_OnlineTest extends PHPUnit_Framework_TestCase
 
     // Because Amazon uses an eventual consistency model, this test period may
     // help avoid *but not guarantee* false negatives
-    protected $_testWaitPeriod = 5;
+    protected $_testWaitPeriod = 2;
 
     /**
      * Sets up this test case
@@ -105,6 +105,8 @@ class Zend_Service_Amazon_SimpleDb_OnlineTest extends PHPUnit_Framework_TestCase
         $this->_testItemNamePrefix = 'TestsZendServiceAmazonSimpleDbItem';
 
         $this->_testAttributeNamePrefix = 'TestsZendServiceAmazonSimpleDbAttribute';
+
+        $this->_wait();
     }
 
     public function testGetAttributes() {
@@ -124,6 +126,7 @@ class Zend_Service_Amazon_SimpleDb_OnlineTest extends PHPUnit_Framework_TestCase
 
             // Now that everything's set up, test it
             $this->_amazon->putAttributes($domainName, $itemName, $attributes);
+            $this->_wait();
 
             // One attribute
             $results = $this->_amazon->getAttributes($domainName, $itemName, $attributeName1);
@@ -164,6 +167,7 @@ class Zend_Service_Amazon_SimpleDb_OnlineTest extends PHPUnit_Framework_TestCase
 
             // Now that everything's set up, test it
             $this->_amazon->putAttributes($domainName, $itemName, $attributes);
+            $this->_wait();
 
             // Multiple attributes
             $results = $this->_amazon->getAttributes($domainName, $itemName);