-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: setting default dimensions as empty array (#37)
* 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
Showing
2 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']); | ||
} | ||
} |