From 1316204267d7abecabf8a24794303ed1c6789e2d Mon Sep 17 00:00:00 2001 From: Cas Leentfaar Date: Sat, 16 May 2015 19:33:44 +0200 Subject: [PATCH] removed modelserializer due to lack of usage --- src/CL/Slack/Serializer/ModelSerializer.php | 63 ------------------- .../Slack/Tests/Model/AbstractModelTest.php | 10 +-- .../Tests/Serializer/ModelSerializerTest.php | 49 --------------- 3 files changed, 6 insertions(+), 116 deletions(-) delete mode 100644 src/CL/Slack/Serializer/ModelSerializer.php delete mode 100644 src/CL/Slack/Tests/Serializer/ModelSerializerTest.php diff --git a/src/CL/Slack/Serializer/ModelSerializer.php b/src/CL/Slack/Serializer/ModelSerializer.php deleted file mode 100644 index 257c5cd6..00000000 --- a/src/CL/Slack/Serializer/ModelSerializer.php +++ /dev/null @@ -1,63 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace CL\Slack\Serializer; - -use CL\Slack\Model\AbstractModel; - -/** - * @author Cas Leentfaar - */ -class ModelSerializer extends AbstractSerializer -{ - /** - * @param AbstractModel $model - * - * @return array - */ - public function serialize(AbstractModel $model) - { - $serializedModel = $this->serializer->serialize($model, 'json'); - if (!$serializedModel || !is_string($serializedModel)) { - throw new \RuntimeException(sprintf( - 'Failed to serialize model; expected it to be a string, got: %s', - var_export($serializedModel, true) - )); - } - - return json_decode($serializedModel, true); - } - - /** - * @param array $model - * @param string $modelClass - * - * @return AbstractModel - */ - public function deserialize(array $model, $modelClass) - { - $modelObject = $this->serializer->deserialize( - json_encode($model), - $modelClass, - 'json' - ); - - if (!($modelObject instanceof AbstractModel)) { - throw new \RuntimeException(sprintf( - 'The serializer expected the model data to be converted into an instance of "%s", got: %s', - $modelClass, - is_object($modelObject) ? 'instance of ' . get_class($modelObject) : gettype($modelObject) - )); - } - - return $modelObject; - } -} diff --git a/src/CL/Slack/Tests/Model/AbstractModelTest.php b/src/CL/Slack/Tests/Model/AbstractModelTest.php index 0e5cf451..c41295ee 100644 --- a/src/CL/Slack/Tests/Model/AbstractModelTest.php +++ b/src/CL/Slack/Tests/Model/AbstractModelTest.php @@ -12,8 +12,9 @@ namespace CL\Slack\Tests\Model; use CL\Slack\Model\AbstractModel; -use CL\Slack\Serializer\ModelSerializer; use CL\Slack\Tests\AbstractTestCase; +use JMS\Serializer\Serializer; +use JMS\Serializer\SerializerBuilder; /** * @author Cas Leentfaar @@ -21,7 +22,7 @@ abstract class AbstractModelTest extends AbstractTestCase { /** - * @var ModelSerializer + * @var Serializer */ protected $serializer; @@ -30,7 +31,8 @@ abstract class AbstractModelTest extends AbstractTestCase */ protected function setUp() { - $this->serializer = new ModelSerializer(); + $metaDir = __DIR__ . '/../../Resources/config/serializer'; + $this->serializer = SerializerBuilder::create()->addMetadataDir($metaDir)->build(); } public function testGetters() @@ -40,7 +42,7 @@ public function testGetters() /** @var AbstractModel $model */ $model = $this->serializer->deserialize( - $modelData, + json_encode($modelData), $modelClass, 'json' ); diff --git a/src/CL/Slack/Tests/Serializer/ModelSerializerTest.php b/src/CL/Slack/Tests/Serializer/ModelSerializerTest.php deleted file mode 100644 index a5e2162f..00000000 --- a/src/CL/Slack/Tests/Serializer/ModelSerializerTest.php +++ /dev/null @@ -1,49 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace CL\Slack\Tests\Serializer; - -use CL\Slack\Model\Channel; -use CL\Slack\Serializer\ModelSerializer; -use CL\Slack\Tests\AbstractTestCase; - -/** - * @author Cas Leentfaar - */ -class ModelSerializerTest extends AbstractTestCase -{ - /** - * @var ModelSerializer - */ - private $modelSerializer; - - protected function setUp() - { - $this->modelSerializer = new ModelSerializer(); - } - - public function testSerialize() - { - $model = new Channel(); - $serializedPayload = $this->modelSerializer->serialize($model); - - $this->assertInternalType('array', $serializedPayload); - } - - public function testDeserialize() - { - $modelData = $this->createChannel(); - $modelClass = 'CL\Slack\Model\Channel'; - $model = $this->modelSerializer->deserialize($modelData, $modelClass); - - $this->assertInstanceOf($modelClass, $model); - } -}