Skip to content

Commit

Permalink
fix: setting default dimensions as empty array (#37)
Browse files Browse the repository at this point in the history
* fix: setting default dimensions as empty array, if not provided (or provided as empty)
#33

* fix: initialization of $dimensions has moved to class scope + added unit tests for payload builder
#33

* fix: styleci
#33

---------

Co-authored-by: Norby Baruani <norby.baruani@gmail.com>
  • Loading branch information
draui and norbybaru authored Jan 16, 2024
1 parent 2c7dd79 commit f6d0307
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Builder/PayloadBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

final class PayloadBuilder implements PayloadBuilderContract
{
protected array $dimensions;
protected array $dimensions = [];

public function __construct(
protected string $measureName,
Expand Down
41 changes: 41 additions & 0 deletions tests/Unit/PayloadBuilderUnitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace NorbyBaru\AwsTimestream\Tests\Unit;

use Illuminate\Support\Carbon;
use NorbyBaru\AwsTimestream\Builder\PayloadBuilder;
use NorbyBaru\AwsTimestream\Tests\TestCase;

class PayloadBuilderUnitTest extends TestCase
{
public function test_it_has_initialized_correctly()
{
// create a time of "2024-01-11T15:49:17+00:00" (that equals to 1704988157000)
$time = Carbon::create(2024, 1, 11, 15, 49, 17, 'UTC');
$payloadBuilder = PayloadBuilder::make(
'test',
1,
$time,
'DOUBLE'
);

try {
$metric = $payloadBuilder->toArray(true);
} catch (\Exception $e) {
$this->fail($e->getMessage());
}

$this->assertIsArray($metric);
$this->assertArrayHasKey('MeasureName', $metric);
$this->assertArrayHasKey('MeasureValue', $metric);
$this->assertArrayHasKey('MeasureValueType', $metric);
$this->assertArrayHasKey('Time', $metric);
$this->assertArrayHasKey('Dimensions', $metric);

$this->assertEquals('test', $metric['MeasureName']);
$this->assertEquals('1', $metric['MeasureValue']);
$this->assertEquals('DOUBLE', $metric['MeasureValueType']);
$this->assertEquals("1704988157000", $metric['Time']);
$this->assertEmpty($metric['Dimensions']);
}
}

0 comments on commit f6d0307

Please sign in to comment.