Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kitar committed Aug 26, 2022
1 parent cc5c2d8 commit baef8cf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Kitar/Dynamodb/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected function createClient(array $config)
'endpoint' => $config['endpoint'] ?? null,
];

if(preg_match('#^https?://#i', $dynamoConfig['endpoint']) === 0){
if (! empty($dynamoConfig['endpoint']) && preg_match('#^https?://#i', $dynamoConfig['endpoint']) === 0) {
$dynamoConfig['endpoint'] = "https://" . $dynamoConfig['endpoint'];
}

Expand Down
26 changes: 26 additions & 0 deletions tests/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,30 @@ public function it_can_forward_call_to_dynamodb_client()
'TableName' => 'User'
]);
}

/** @test */
public function it_prepends_default_protocol_if_not_given()
{
$connection = new Connection(['endpoint' => 'examples.com']);
$this->assertEquals($connection->getClient()->getEndpoint()->getScheme(), 'https');
$this->assertEquals($connection->getClient()->getEndpoint()->getHost(), 'examples.com');
$this->assertEquals($this->connection->getClient()->getEndpoint()->getScheme(), 'https');
$this->assertEquals($this->connection->getClient()->getEndpoint()->getHost(), 'dynamodb.us-east-1.amazonaws.com');
}

/** @test */
public function it_dont_prepends_default_protocol_if_http_given()
{
$connection = new Connection(['endpoint' => 'http://examples.com']);
$this->assertEquals($connection->getClient()->getEndpoint()->getScheme(), 'http');
$this->assertEquals($connection->getClient()->getEndpoint()->getHost(), 'examples.com');
}

/** @test */
public function it_dont_prepends_default_protocol_if_https_given()
{
$connection = new Connection(['endpoint' => 'https://examples.com']);
$this->assertEquals($connection->getClient()->getEndpoint()->getScheme(), 'https');
$this->assertEquals($connection->getClient()->getEndpoint()->getHost(), 'examples.com');
}
}

0 comments on commit baef8cf

Please sign in to comment.