|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace NorbyBaru\AwsTimestream\Tests\Unit; |
| 4 | + |
| 5 | +use Illuminate\Support\Carbon; |
| 6 | +use NorbyBaru\AwsTimestream\Builder\PayloadBuilder; |
| 7 | +use NorbyBaru\AwsTimestream\Tests\TestCase; |
| 8 | + |
| 9 | +class PayloadBuilderUnitTest extends TestCase |
| 10 | +{ |
| 11 | + public function test_it_has_initialized_correctly() |
| 12 | + { |
| 13 | + // create a time of "2024-01-11T15:49:17+00:00" (that equals to 1704988157000) |
| 14 | + $time = Carbon::create(2024, 1, 11, 15, 49, 17, 'UTC'); |
| 15 | + $payloadBuilder = PayloadBuilder::make( |
| 16 | + 'test', |
| 17 | + 1, |
| 18 | + $time, |
| 19 | + 'DOUBLE' |
| 20 | + ); |
| 21 | + |
| 22 | + try { |
| 23 | + $metric = $payloadBuilder->toArray(true); |
| 24 | + } catch (\Exception $e) { |
| 25 | + $this->fail($e->getMessage()); |
| 26 | + } |
| 27 | + |
| 28 | + $this->assertIsArray($metric); |
| 29 | + $this->assertArrayHasKey('MeasureName', $metric); |
| 30 | + $this->assertArrayHasKey('MeasureValue', $metric); |
| 31 | + $this->assertArrayHasKey('MeasureValueType', $metric); |
| 32 | + $this->assertArrayHasKey('Time', $metric); |
| 33 | + $this->assertArrayHasKey('Dimensions', $metric); |
| 34 | + |
| 35 | + $this->assertEquals('test', $metric['MeasureName']); |
| 36 | + $this->assertEquals('1', $metric['MeasureValue']); |
| 37 | + $this->assertEquals('DOUBLE', $metric['MeasureValueType']); |
| 38 | + $this->assertEquals("1704988157000", $metric['Time']); |
| 39 | + $this->assertEmpty($metric['Dimensions']); |
| 40 | + } |
| 41 | +} |
0 commit comments