public function testPutExpected()
 {
     $id = intval(getenv('ITEM_ID'));
     $item = new Item(getenv('DY_TABLE'));
     $item['id'] = $id;
     $item['name'] = 'test';
     $item['strings'] = array('test1', 'test2');
     $item['numbers'] = array(4, 5, 6);
     $this->conn->put($item);
     $expected = new Expected();
     $expected['strings'] = new ExpectedAttribute(array('test1', 'test2'));
     $expected['non_existent'] = new ExpectedAttribute(false);
     $context = new Context\Put();
     $context->setExpected($expected);
     $context->setReturnValues(ReturnValue::ALL_OLD);
     $newItem = new Item(getenv('DY_TABLE'));
     $newItem['id'] = $id;
     $newItem['name'] = 'test';
     $newItem['strings'] = array('test1', 'test2', 'test3');
     $newItem['numbers'] = array(4, 5, 6, 7, 8, 9);
     $attributes = $this->conn->put($item, $context);
     $this->assertNotNull($attributes);
 }
 /**
  * Add an item to DynamoDB via the put_item call
  * @param Item $item
  * @param Context\Put|null $context The call context
  * @return array|null
  * @throws Exception\AttributesException
  */
 public function put(Item $item, Context\Put $context = null)
 {
     $table = $item->getTable();
     if (null !== $this->logger) {
         $this->log('Put on table ' . $table);
     }
     if (empty($table)) {
         throw new \Riverline\DynamoDB\Exception\AttributesException('Item do not have table defined');
     }
     $attributes = array();
     foreach ($item as $name => $attribute) {
         /** @var $attribute \Riverline\DynamoDB\Attribute */
         if ("" !== $attribute->getValue()) {
             // Only not empty string
             $attributes[$name] = $attribute->getForDynamoDB();
         }
     }
     $parameters = array('TableName' => $table, 'Item' => $attributes);
     if (null !== $context) {
         $parameters += $context->getForDynamoDB();
     }
     if (null !== $this->logger) {
         $this->log('Put request paramaters : ' . print_r($parameters, true), Logger::DEBUG);
     }
     $response = $this->connector->putItem($parameters);
     if (null !== $this->logger) {
         $this->log('Put request response : ' . print_r($response, true), Logger::DEBUG);
     }
     // Update write counter
     $this->addConsumedWriteUnits($table, floatval($response['ConsumedCapacityUnits']));
     return $this->populateAttributes($response);
 }