Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: nullabe arrays of decoded ids were retrieved as [null] #211

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Traits/HashIdTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ private function locateAndDecodeIds($requestData, $key): mixed
*/
private function processField($data, $keysTodo, $currentFieldName): mixed
{
// is the current field a null?! we can give it back and chill out
if(is_null($data)) {
return $data;
}

// check if there are no more fields to be processed
if (empty($keysTodo)) {
// there are no more keys left - so basically we need to decode this entry
Expand Down
36 changes: 36 additions & 0 deletions tests/Unit/Traits/HashIdTraitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Apiato\Core\Tests\Unit\Traits;

use Apiato\Core\Tests\Unit\UnitTestCase;
use Apiato\Core\Traits\HashIdTrait;
use PHPUnit\Framework\Attributes\CoversClass;
use ReflectionClass;

#[CoversClass(HashIdTrait::class)]
class HashIdTraitTest extends UnitTestCase
{
private $trait;

public function setUp(): void
{
parent::setUp();

$this->trait = new class {
use HashIdTrait;
};
}

public function testProcessFieldShouldNotWrapANullInAnArray(): void
{
$data = null;
$keysTodo = ['*'];
$currentFieldName = null;
$reflection = new ReflectionClass($this->trait);
$method = $reflection->getMethod('processField');

$result = $method->invoke($this->trait, $data, $keysTodo, $currentFieldName);

$this->assertNull($result);
}
}
Loading