From 33a7d9c68544f8533ca2b1366cb90fcd55e3a6d5 Mon Sep 17 00:00:00 2001 From: Fabio Capucci Date: Fri, 18 Apr 2025 11:06:23 +0200 Subject: [PATCH] map drop keys to snake case in toArray --- src/Drop.php | 6 +++--- tests/Integration/DropTest.php | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Drop.php b/src/Drop.php index 589fbe4..cb0c644 100644 --- a/src/Drop.php +++ b/src/Drop.php @@ -26,15 +26,15 @@ public function toArray(): array $result = []; foreach ($this->getMetadata()->properties as $property) { - $result[$property] = $this->{$property}; + $result[Str::snake($property)] = $this->{$property}; } foreach ($this->getMetadata()->dynamicProperties as $property) { - $result[$property] = $this->{$property}; + $result[Str::snake($property)] = $this->{$property}; } foreach ($this->getMetadata()->invokableMethods as $method) { - $result[$method] = $this->{$method}; + $result[Str::snake($method)] = $this->{$method}; } return $result; diff --git a/tests/Integration/DropTest.php b/tests/Integration/DropTest.php index 03c4c0e..70ea8f4 100644 --- a/tests/Integration/DropTest.php +++ b/tests/Integration/DropTest.php @@ -114,10 +114,10 @@ $drop = new ProductDrop; $drop->setContext($context); expect($drop->toArray()) - ->toHaveKeys(['productName', 'text', 'catchAll', 'context']) - ->productName->toBe('Product') + ->toHaveKeys(['product_name', 'text', 'catch_all', 'context']) + ->product_name->toBe('Product') ->text->toBeInstanceOf(\Keepsuit\Liquid\Tests\Stubs\TextDrop::class) - ->catchAll->toBeInstanceOf(\Keepsuit\Liquid\Tests\Stubs\CatchAllDrop::class) + ->catch_all->toBeInstanceOf(\Keepsuit\Liquid\Tests\Stubs\CatchAllDrop::class) ->context->toBe($context); });