Skip to content

Commit

Permalink
fix enum for php8
Browse files Browse the repository at this point in the history
  • Loading branch information
norbybaru committed Oct 12, 2023
1 parent 616b68b commit 67e58bc
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/Builder/CommonPayloadBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/Builder/PayloadBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 10 additions & 6 deletions src/Enum/ValueTypeEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
5 changes: 3 additions & 2 deletions tests/Feature/PayloadWriterFeatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 67e58bc

Please sign in to comment.