From 67e58bce8dd6e65721b1f26a80a3de8d25da7114 Mon Sep 17 00:00:00 2001 From: Norby Baruani Date: Thu, 12 Oct 2023 10:07:49 +0200 Subject: [PATCH] fix enum for php8 --- composer.json | 3 ++- src/Builder/CommonPayloadBuilder.php | 2 +- src/Builder/PayloadBuilder.php | 4 ++-- src/Enum/ValueTypeEnum.php | 16 ++++++++++------ tests/Feature/PayloadWriterFeatureTest.php | 5 +++-- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/composer.json b/composer.json index 71f6cf4..81a9186 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,8 @@ "require": { "php": "^8.0", "aws/aws-sdk-php": "^3.209", - "illuminate/support": "^8.0|^9.52|^10.0" + "illuminate/support": "^8.0|^9.52|^10.0", + "spatie/enum": "^3.13" }, "minimum-stability": "dev", "prefer-stable": true, diff --git a/src/Builder/CommonPayloadBuilder.php b/src/Builder/CommonPayloadBuilder.php index c333de7..33eeec4 100644 --- a/src/Builder/CommonPayloadBuilder.php +++ b/src/Builder/CommonPayloadBuilder.php @@ -20,7 +20,7 @@ public function setCommonDimensions(string $name, mixed $value): self $this->commonDimensions[] = [ 'Name' => $name, 'Value' => $value, - 'DimensionValueType' => ValueTypeEnum::VARCHAR->value, + 'DimensionValueType' => ValueTypeEnum::VARCHAR()->value, ]; return $this; diff --git a/src/Builder/PayloadBuilder.php b/src/Builder/PayloadBuilder.php index cbf171f..cf29949 100644 --- a/src/Builder/PayloadBuilder.php +++ b/src/Builder/PayloadBuilder.php @@ -70,12 +70,12 @@ public function setVersion(int $version): self return $this; } - public function setMultiMeasuresValues(string $name, mixed $value, ValueTypeEnum $type = ValueTypeEnum::VARCHAR): self + public function setMultiMeasuresValues(string $name, mixed $value, ?ValueTypeEnum $type = null): self { $this->measureValues[] = [ 'Name' => $name, 'Value' => $value, - 'Type' => $type->value, + 'Type' => $type?->value ?? ValueTypeEnum::VARCHAR()->value, ]; return $this; diff --git a/src/Enum/ValueTypeEnum.php b/src/Enum/ValueTypeEnum.php index 951058e..3fd0c2c 100644 --- a/src/Enum/ValueTypeEnum.php +++ b/src/Enum/ValueTypeEnum.php @@ -2,11 +2,15 @@ namespace NorbyBaru\AwsTimestream\Enum; -enum ValueTypeEnum: string +use Spatie\Enum\Enum; + +/** + * @method static self DOUBLE() + * @method static self BIGINT() + * @method static self VARCHAR() + * @method static self BOOLEAN() + * @method static self TIMESTAMP() + */ +class ValueTypeEnum extends Enum { - case DOUBLE = 'DOUBLE'; - case BIGINT = 'BIGINT'; - case VARCHAR = 'VARCHAR'; - case BOOLEAN = 'BOOLEAN'; - case TIMESTAMP = 'TIMESTAMP'; } diff --git a/tests/Feature/PayloadWriterFeatureTest.php b/tests/Feature/PayloadWriterFeatureTest.php index 2955b17..0ff86ba 100644 --- a/tests/Feature/PayloadWriterFeatureTest.php +++ b/tests/Feature/PayloadWriterFeatureTest.php @@ -29,7 +29,8 @@ public function test_it_should_ingest_multi_measure_records() ->setDimensions(name: $data[2], value: $data[3]) ->setDimensions(name: $data[4], value: $data[5]) ->setMultiMeasuresValues(name: $data[6], value: $data[7], type: ValueTypeEnum::from($data[8])) - ->setMultiMeasuresValues(name: $data[9], value: $data[10], type: ValueTypeEnum::from($data[11])); + ->setMultiMeasuresValues(name: $data[9], value: $data[10], type: ValueTypeEnum::from($data[11])) + ->setMultiMeasuresValues(name: 'agent', value: $this->faker->userAgent, type: ValueTypeEnum::VARCHAR()); $payload->setVersion(Carbon::now()->subMilliseconds($index * 50)->timestamp); @@ -90,7 +91,7 @@ public function test_it_should_batch_ingest_data() $common = CommonPayloadBuilder::make() ->setCommonDimensions(name: 'processor', value: $this->faker->linuxProcessor) ->setCommonDimensions(name: 'mac_address', value: $this->faker->macAddress) - ->setCommonMeasureValueType(ValueTypeEnum::VARCHAR) + ->setCommonMeasureValueType(ValueTypeEnum::VARCHAR()) ->setCommonTime(Carbon::now()) ->toArray();