Skip to content

Commit

Permalink
Merge pull request #78 from TheDragonCode/3.x
Browse files Browse the repository at this point in the history
Fixed an error in obtaining a key name from a class without public properties
  • Loading branch information
andrey-helldar authored Dec 3, 2023
2 parents 6c78e6e + 0b73bca commit 5e2fab1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/Concerns/Arrayable.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ protected function toArray($value): array
->map(fn ($value) => Instance::of($value, Carbon::class) ? $value->toIso8601String() : $value)
->map(fn ($value) => Instance::of($value, FormRequest::class) ? $value->validated() : $value)
->map(fn ($value) => Instance::of($value, BackedEnum::class) ? ($value->value ?? $value->name) : $value)
->map(fn ($value) => is_object($value) ? (Arr::resolve($value) ?: get_class($value)) : $value)
->resolve()
->toArray();
}
Expand Down
9 changes: 9 additions & 0 deletions tests/Fixtures/Simple/CustomObjectWithoutProperties.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Tests\Fixtures\Simple;

class CustomObjectWithoutProperties
{
}
11 changes: 6 additions & 5 deletions tests/Support/KeyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Tests\Fixtures\Enums\WithValueEnum;
use Tests\Fixtures\Models\User;
use Tests\Fixtures\Simple\CustomObject;
use Tests\Fixtures\Simple\CustomObjectWithoutProperties;
use Tests\TestCase;

class KeyTest extends TestCase
Expand Down Expand Up @@ -103,13 +104,13 @@ public function testArrayable()
$this->assertSame($expected, $key);
}

public function testCustomObject()
public function testCustomObjects()
{
$key = Key::get(':', [new CustomObject()]);
$key1 = Key::get(':', [new CustomObject()]);
$key2 = Key::get(':', [new CustomObjectWithoutProperties()]);

$expected = 'b58721335d52d66a9486072fe3383ccf';

$this->assertSame($expected, $key);
$this->assertSame('b58721335d52d66a9486072fe3383ccf', $key1);
$this->assertSame('9be04f864d3649e49e892638361d5d49', $key2);
}

public function testMultiObjectArrays()
Expand Down

0 comments on commit 5e2fab1

Please sign in to comment.