From 5345eb43c4e2d558ec8f16e4643da98e01734fe2 Mon Sep 17 00:00:00 2001 From: Vlad Varlamov Date: Fri, 8 Nov 2024 15:56:27 +0400 Subject: [PATCH] Add typecast to string in the ORM schema (#77) --- src/Generator/GenerateTypecast.php | 4 ++++ tests/Schema/Generator/TypecastGeneratorTest.php | 1 + 2 files changed, 5 insertions(+) diff --git a/src/Generator/GenerateTypecast.php b/src/Generator/GenerateTypecast.php index faa51bb..58a88fc 100644 --- a/src/Generator/GenerateTypecast.php +++ b/src/Generator/GenerateTypecast.php @@ -73,6 +73,10 @@ private function typecast(AbstractColumn $column) return 'datetime'; } + if ($column->getType() === AbstractColumn::STRING) { + return 'string'; + } + return null; } } diff --git a/tests/Schema/Generator/TypecastGeneratorTest.php b/tests/Schema/Generator/TypecastGeneratorTest.php index 1c49bc4..a21f8ee 100644 --- a/tests/Schema/Generator/TypecastGeneratorTest.php +++ b/tests/Schema/Generator/TypecastGeneratorTest.php @@ -28,6 +28,7 @@ public function testCompiledUser(): void $this->assertSame('int', $schema['user'][Schema::TYPECAST]['p_id']); $this->assertSame('float', $schema['user'][Schema::TYPECAST]['p_balance']); $this->assertSame('datetime', $schema['user'][Schema::TYPECAST]['p_created_at']); + $this->assertSame('string', $schema['user'][Schema::TYPECAST]['p_name']); $this->assertTrue(in_array($schema['user'][Schema::TYPECAST]['p_id'], ['int', 'bool'])); }