Skip to content

Commit

Permalink
Chipping away at some code coverage improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremeamia committed Apr 28, 2015
1 parent dbb0c04 commit b8bfed9
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/CloudSearch/CloudSearchClient.php
Expand Up @@ -27,7 +27,7 @@ public function createDomainClient($domainName, array $config = [])
$config += [
'credentials' => $this->getCredentials(),
'scheme' => 'https',
'version' => 'latest',
'version' => 'latest'
];

// Create an absolute URI for the endpoint.
Expand Down
25 changes: 9 additions & 16 deletions src/CloudTrail/LogFileIterator.php
Expand Up @@ -307,23 +307,16 @@ private function applyDateFilter($objectsIterator, $startDate, $endDate)
// If either a start or end date was provided, filter out dates that
// don't match the date range.
if ($startDate || $endDate) {
$objectsIterator = new \CallbackFilterIterator(
$objectsIterator,
function ($object) use ($startDate, $endDate) {
if (!preg_match(
'/[0-9]{8}T[0-9]{4}Z/',
$object['Key'],
$matches)
) {
return false;
}

$date = strtotime($matches[0]);

return (!$startDate || $date >= $startDate) &&
(!$endDate || $date <= $endDate);
$fn = function ($object) use ($startDate, $endDate) {
if (!preg_match('/[0-9]{8}T[0-9]{4}Z/', $object['Key'], $m)) {
return false;
}
);
$date = strtotime($m[0]);

return (!$startDate || $date >= $startDate)
&& (!$endDate || $date <= $endDate);
};
$objectsIterator = new \CallbackFilterIterator($objectsIterator, $fn);
}

return $objectsIterator;
Expand Down
4 changes: 2 additions & 2 deletions src/DynamoDb/StandardSessionConnection.php
Expand Up @@ -96,7 +96,7 @@ public function delete($id)
public function deleteExpired()
{
// Create a Scan iterator for finding expired session items
$scan = $this->client->getIterator('Scan', [
$scan = $this->client->getPaginator('Scan', [
'TableName' => $this->config['table_name'],
'AttributesToGet' => [$this->config['hash_key']],
'ScanFilter' => [
Expand All @@ -114,7 +114,7 @@ public function deleteExpired()
$batch = new WriteRequestBatch($this->client, $this->config['batch_config']);

// Perform Scan and BatchWriteItem (delete) operations as needed
foreach ($scan as $item) {
foreach ($scan->search('Items') as $item) {
$batch->delete(
[$this->config['hash_key'] => $item[$this->config['hash_key']]],
$this->config['table_name']
Expand Down
3 changes: 3 additions & 0 deletions tests/CloudTrail/LogFileIteratorTest.php
Expand Up @@ -106,6 +106,9 @@ private function getMockS3Client()
<Contents>
<Key>AWSLogs/12345/CloudTrail/us-east-1/2013/11/15/foo-20131115T1453Z-log.json.gz</Key>
</Contents>
<Contents>
<Key>AWSLogs/12345/CloudTrail/us-east-1/2013/11/15/foo-20131115TFILTERME-log.json.gz</Key>
</Contents>
<Contents>
<Key>AWSLogs/12345/CloudTrail/us-east-1/2013/11/28/foo-20131128T1822Z-log.json.gz</Key>
</Contents>
Expand Down
19 changes: 15 additions & 4 deletions tests/DynamoDb/LockingSessionConnectionTest.php
@@ -1,6 +1,7 @@
<?php
namespace Aws\Test\DynamoDb;

use Aws\DynamoDb\Exception\DynamoDbException;
use Aws\DynamoDb\LockingSessionConnection;
use Aws\Result;
use Aws\Test\UsesServiceTrait;
Expand All @@ -16,10 +17,7 @@ public function testReadRetrievesItemData()
{
$client = $this->getTestSdk()->createDynamoDb();
$this->addMockResults($client, [
$this->createMockAwsException(
'ConditionalCheckFailedException',
'Aws\DynamoDb\Exception\DynamoDbException'
),
$this->createMockAwsException('ConditionalCheckFailedException', DynamoDbException::class),
new Result(['Attributes' => [
'sessionid' => ['S' => 'session1'],
'otherkey' => ['S' => 'foo'],
Expand All @@ -34,4 +32,17 @@ public function testReadRetrievesItemData()
$data
);
}

public function testBailsOnUnexpectedException()
{
$client = $this->getTestSdk()->createDynamoDb();
$this->addMockResults($client, [
$this->createMockAwsException('Unexpected', DynamoDbException::class),
]);

$connection = new LockingSessionConnection($client);
$data = $connection->read('session1');

$this->assertEquals(null, $data);
}
}
23 changes: 10 additions & 13 deletions tests/DynamoDb/StandardSessionConnectionTest.php
Expand Up @@ -94,7 +94,7 @@ public function testWriteReturnsFalseOnFailure()
$this->assertFalse($return);
}

public function testDeleteReturnsBoolBasedOnRSuccess()
public function testDeleteReturnsBoolBasedOnSuccess()
{
$client = $this->getTestSdk()->createDynamoDb();
$this->addMockResults($client, [
Expand All @@ -111,32 +111,29 @@ public function testDeleteReturnsBoolBasedOnRSuccess()
$this->assertFalse($return);
}

public function testDeleteReturnsBoolBasedOnSuccess()
public function testDeleteExpiredReturnsBoolBasedOnSuccess()
{
$client = $this->getTestSdk()->createDynamoDb();
$this->addMockResults($client, [
new Result([]),
new Result(['LastEvaluatedKey' => ['foo' => ['S' => 'bar']]]),
new Result(['Items' => [
['id' => ['S' => 'foo']],
['id' => ['S' => 'bar']],
['id' => ['S' => 'baz']],
]])
]]),
new Result(),
]);

$commands = [];
$client->getHandlerList()->append(
'build',
Middleware::tap(function (CommandInterface $command) {
static $called = 0;
if (++$called === 1) {
$this->assertEquals('Scan', $command->getName());
} elseif ($called === 2) {
$this->assertEquals('Scan', $command->getName());
} else {
$this->fail('Unexpected state.');
}
Middleware::tap(function (CommandInterface $command) use (&$commands) {
$commands[] = $command->getName();
})
);

(new StandardSessionConnection($client))->deleteExpired();

$this->assertEquals(['Scan', 'Scan', 'BatchWriteItem'], $commands);
}
}

0 comments on commit b8bfed9

Please sign in to comment.