From 7fc89271f32462b638c5d2bbb980551fdbc3b48c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Mon, 11 Feb 2019 19:34:52 +0100 Subject: [PATCH] Fix #28 associative arrays being converted into objects --- src/TenantManager.php | 6 +++--- tests/TenantStorageTest.php | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/TenantManager.php b/src/TenantManager.php index c19dfa1a..011cd52f 100644 --- a/src/TenantManager.php +++ b/src/TenantManager.php @@ -231,7 +231,7 @@ class TenantManager return $this->jsonDecodeArrayValues($this->storage->getMany($uuid, $key)); } - return json_decode($this->storage->get($uuid, $key)); + return json_decode($this->storage->get($uuid, $key), true); } /** @@ -259,7 +259,7 @@ class TenantManager } if (! is_null($value)) { - return $target[$key] = json_decode($this->storage->put($uuid, $key, json_encode($value))); + return $target[$key] = json_decode($this->storage->put($uuid, $key, json_encode($value)), true); } if (! is_array($key)) { @@ -290,7 +290,7 @@ class TenantManager protected function jsonDecodeArrayValues(array $array) { array_walk($array, function (&$value, $key) { - $value = json_decode($value); + $value = json_decode($value, true); }); return $array; diff --git a/tests/TenantStorageTest.php b/tests/TenantStorageTest.php index 5960ee4a..69388b38 100644 --- a/tests/TenantStorageTest.php +++ b/tests/TenantStorageTest.php @@ -93,6 +93,15 @@ class TenantStorageTest extends TestCase $this->assertSame([1, 2], tenant()->get('foo')); } + /** @test */ + public function associative_arrays_can_be_stored() + { + $data = ['a' => 'b', 'c' => 'd']; + tenant()->put('foo', $data); + + $this->assertSame($data, tenant()->get('foo')); + } + /** @test */ public function put_returns_the_value_when_two_arguments_are_used() {