Skip to content

Commit

Permalink
Release 1.0.6 - Also set Case insentive properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
vanengers committed Oct 16, 2023
1 parent 7f5f0a8 commit 7589a4b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/PhpJsonObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public function fromArray($data)
call_user_func_array([$this, 'set' . ucfirst(strtolower($key))], ['data' => $value]);
} else if (property_exists($this, strtolower($key))) {
$this->{strtolower($key)} = $value;
} else if (property_exists($this, $key)) {
$this->{$key} = $value;
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions tests/Mocks/TestCaseInsensitiveObject.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Vanengers\PhpJsonObjectLibrary\Tests\Mocks;

use Vanengers\PhpJsonObjectLibrary\PhpJsonObject;

class TestCaseInsensitiveObject extends PhpJsonObject
{
public $createdAt;
public $ThisHasSomeCaseInsentiveFields;
}
26 changes: 26 additions & 0 deletions tests/toArray/CaseInsentiveTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Vanengers\PhpJsonObjectLibrary\Tests\toArray;

use PHPUnit\Framework\TestCase;
use Vanengers\PhpJsonObjectLibrary\Tests\Mocks\TestCaseInsensitiveObject;
use Vanengers\PhpJsonObjectLibrary\Tests\Mocks\TestObject;

class CaseInsentiveTest extends TestCase
{
public function testToArrayGivesResultFieldsWithResults()
{
$createdAt = 'cvdnfvgdfvghj344';
$caseInsentive = 'HJGdgfsjkftghjkewrtjk34hfg;';
$test = new TestCaseInsensitiveObject([
"createdAt" => $createdAt,
"ThisHasSomeCaseInsentiveFields" => $caseInsentive
]);
$result = $test->toArray();

$this->assertArrayHasKey("createdAt", $result);
$this->assertArrayHasKey("ThisHasSomeCaseInsentiveFields", $result);
$this->assertEquals($createdAt, $result["createdAt"]);
$this->assertEquals($caseInsentive, $result["ThisHasSomeCaseInsentiveFields"]);
}
}

0 comments on commit 7589a4b

Please sign in to comment.