From d40ee11ef5313e20ee2bfc8d164c555bee46313d Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Thu, 8 May 2014 11:55:04 +0100 Subject: [PATCH] Scope entity is json serializable --- src/Entity/ScopeEntity.php | 14 +++++++++++++- tests/Entity/ScopeEntityTest.php | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Entity/ScopeEntity.php b/src/Entity/ScopeEntity.php index a4d7f735..0740384b 100644 --- a/src/Entity/ScopeEntity.php +++ b/src/Entity/ScopeEntity.php @@ -16,7 +16,7 @@ use League\OAuth2\Server\AbstractServer; /** * Scope entity class */ -class ScopeEntity +class ScopeEntity implements \JsonSerializable { /** * Scope identifier @@ -89,4 +89,16 @@ class ScopeEntity { return $this->description; } + + /** + * Returns a JSON object when entity is passed into json_encode + * @return array + */ + public function jsonSerialize() + { + return [ + 'id' => $this->getId(), + 'description' => $this->getDescription() + ]; + } } diff --git a/tests/Entity/ScopeEntityTest.php b/tests/Entity/ScopeEntityTest.php index a734c310..cdd39040 100644 --- a/tests/Entity/ScopeEntityTest.php +++ b/tests/Entity/ScopeEntityTest.php @@ -16,5 +16,7 @@ class ScopeTest extends \PHPUnit_Framework_TestCase $this->assertEquals('foobar', $scope->getId()); $this->assertEquals('barfoo', $scope->getDescription()); + + $this->assertTrue(is_array($scope->jsonSerialize())); } }