From f6d03079bcd45dd6dc2e534e4509a55ac5d84a43 Mon Sep 17 00:00:00 2001 From: draui Date: Tue, 16 Jan 2024 21:34:04 +0200 Subject: [PATCH] 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 --- src/Builder/PayloadBuilder.php | 2 +- tests/Unit/PayloadBuilderUnitTest.php | 41 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 tests/Unit/PayloadBuilderUnitTest.php diff --git a/src/Builder/PayloadBuilder.php b/src/Builder/PayloadBuilder.php index 08b92df..45edcb0 100644 --- a/src/Builder/PayloadBuilder.php +++ b/src/Builder/PayloadBuilder.php @@ -7,7 +7,7 @@ final class PayloadBuilder implements PayloadBuilderContract { - protected array $dimensions; + protected array $dimensions = []; public function __construct( protected string $measureName, diff --git a/tests/Unit/PayloadBuilderUnitTest.php b/tests/Unit/PayloadBuilderUnitTest.php new file mode 100644 index 0000000..b709898 --- /dev/null +++ b/tests/Unit/PayloadBuilderUnitTest.php @@ -0,0 +1,41 @@ +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']); + } +}