Skip to content

Commit

Permalink
[SimpleDb] Updating regular expressions for attribute commands. Addin…
Browse files Browse the repository at this point in the history
…g more test coverage.
  • Loading branch information
mtdowling committed Apr 10, 2011
1 parent 63dc37f commit f6cc0b1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion SimpleDb/Command/AbstractAttributeCommand.php
Expand Up @@ -27,7 +27,7 @@ protected function build()
parent::build();
$this->request->getQuery()->set('ItemName', $this->get('item_name'));

foreach ($this->getAll('/^Attribute(Name)*\.[0-9]+.*+$/', Collection::MATCH_REGEX) as $key => $value) {
foreach ($this->getAll('/^Attribute(Name)*\.[0-9]+.*$/', Collection::MATCH_REGEX) as $key => $value) {
$this->request->getQuery()->set($key, $value);
}
}
Expand Down
6 changes: 3 additions & 3 deletions SimpleDb/Command/PutAttributes.php
Expand Up @@ -30,7 +30,7 @@ class PutAttributes extends AbstractAttributeCommand
protected function build()
{
parent::build();
foreach ($this->getAll('/Expected\.[0-9]+[.*]+/', Collection::MATCH_REGEX) as $key => $value) {
foreach ($this->getAll('/Expected\.[0-9]+.*/', Collection::MATCH_REGEX) as $key => $value) {
$this->request->getQuery()->set($key, $value);
}
}
Expand All @@ -47,7 +47,7 @@ protected function build()
*/
public function addAttribute($name, $value, $replace = false)
{
$count = (int) count($this->getAll('/^Attribute(Name)*\.[0-9]+[.*]+/', Collection::MATCH_REGEX));
$count = (int) count($this->getAll('/^Attribute(Name)*\.[0-9]+\.Name$/', Collection::MATCH_REGEX));
$this->set("Attribute.{$count}.Name", (string) $name);
$this->set("Attribute.{$count}.Value", (string) $value);
$this->set("Attribute.{$count}.Replace", ($replace) ? 'true' : 'false');
Expand Down Expand Up @@ -85,7 +85,7 @@ public function addExpected($name, $value, $exists = false)
public function setAttributes(array $attributes, $replace = false)
{
// Remove all previously set attributes
foreach ($this->getAll('/^Attribute\.[0-9]+\.Name$/', Collection::MATCH_REGEX) as $key => $value) {
foreach ($this->getAll('/^Attribute\.[0-9]+\..*/', Collection::MATCH_REGEX) as $key => $value) {
$this->remove($key);
}

Expand Down
9 changes: 7 additions & 2 deletions Tests/SimpleDb/Command/PutAttributesTest.php
Expand Up @@ -21,7 +21,7 @@ class PutAttributesTest extends \Guzzle\Tests\GuzzleTestCase
public function testHoldsAttributes()
{
$client = $this->getServiceBuilder()->get('test.simple_db');
$command = new \Guzzle\Service\Aws\SimpleDb\Command\PutAttributes();
$command = $client->getCommand('put_attributes');
$this->assertSame($command, $command->setDomain('test'));
$this->assertSame($command, $command->setItemName('item'));
$this->assertSame($command, $command->addExpected('attr_1', 'value_1', true));
Expand All @@ -43,6 +43,11 @@ public function testHoldsAttributes()
'attr_2' => array('value_2', 'value_3')
), true));

$this->assertSame($command, $command->setAttributes(array(
'attr_1' => 'value_1',
'attr_2' => array('value_2', 'value_3')
), true));

$this->assertEquals(array(
'Attribute.0.Value' => 'value_1',
'Attribute.0.Replace' => 'true',
Expand All @@ -65,7 +70,7 @@ public function testHoldsAttributes()
public function testPreparesRequest()
{
$client = $this->getServiceBuilder()->get('test.simple_db');
$command = new \Guzzle\Service\Aws\SimpleDb\Command\PutAttributes();
$command = $client->getCommand('put_attributes');
$this->assertSame($command, $command->setDomain('test'));
$this->assertSame($command, $command->setItemName('item'));
$command->addExpected('attr_1', 'value_1', true);
Expand Down

0 comments on commit f6cc0b1

Please sign in to comment.