From c41356e9bbb0f28b99ce16ca544b468fbd9921fd Mon Sep 17 00:00:00 2001 From: Miguel Date: Sun, 19 Jun 2016 18:19:37 +0200 Subject: [PATCH] Add some tests. --- tests/unit/SerializerFactoryTest.php | 46 +++++++++++++++++++ .../unit/Serializers/JsonSerizalizerTest.php | 30 ++++++++++++ .../unit/Serializers/NullSerizalizerTest.php | 30 ++++++++++++ tests/unit/Serializers/PhpSerizalizerTest.php | 30 ++++++++++++ 4 files changed, 136 insertions(+) create mode 100644 tests/unit/SerializerFactoryTest.php create mode 100644 tests/unit/Serializers/JsonSerizalizerTest.php create mode 100644 tests/unit/Serializers/NullSerizalizerTest.php create mode 100644 tests/unit/Serializers/PhpSerizalizerTest.php diff --git a/tests/unit/SerializerFactoryTest.php b/tests/unit/SerializerFactoryTest.php new file mode 100644 index 0000000..7eafbb9 --- /dev/null +++ b/tests/unit/SerializerFactoryTest.php @@ -0,0 +1,46 @@ +assertTrue(SerializerFactory::bySerializedContentType($contentType) instanceof $expectedSerializerClass); + } + + /** + * @expectedException \Retrinko\Serializer\Exceptions\Exception + */ + public function test_bySerializedContentType_withUnsupportedContentType_thowsException() + { + SerializerFactory::bySerializedContentType('unsupported content type'); + } +} \ No newline at end of file diff --git a/tests/unit/Serializers/JsonSerizalizerTest.php b/tests/unit/Serializers/JsonSerizalizerTest.php new file mode 100644 index 0000000..43aad10 --- /dev/null +++ b/tests/unit/Serializers/JsonSerizalizerTest.php @@ -0,0 +1,30 @@ +assertEquals($expected, (new JsonSerializer())->getSerializedContentType()); + } + + public function test_serialize_retrunsProperValue() + { + $test = ['a', 'b', 'c']; + $expected = json_encode($test); + $this->assertEquals($expected, (new JsonSerializer())->serialize($test)); + } + + public function test_unserialize_retrunsProperValue() + { + $test = '["a","b","c"]'; + $expected = json_decode($test, true); + $this->assertEquals($expected, (new JsonSerializer())->unserialize($test)); + } +} \ No newline at end of file diff --git a/tests/unit/Serializers/NullSerizalizerTest.php b/tests/unit/Serializers/NullSerizalizerTest.php new file mode 100644 index 0000000..d010ce0 --- /dev/null +++ b/tests/unit/Serializers/NullSerizalizerTest.php @@ -0,0 +1,30 @@ +assertEquals($expected, (new NullSerializer())->getSerializedContentType()); + } + + public function test_serialize_retrunsProperValue() + { + $test = ['a', 'b', 'c']; + $expected = $test; + $this->assertEquals($expected, (new NullSerializer())->serialize($test)); + } + + public function test_unserialize_retrunsProperValue() + { + $test = '["a","b","c"]'; + $expected = $test; + $this->assertEquals($expected, (new NullSerializer())->unserialize($test)); + } +} \ No newline at end of file diff --git a/tests/unit/Serializers/PhpSerizalizerTest.php b/tests/unit/Serializers/PhpSerizalizerTest.php new file mode 100644 index 0000000..3d8bb8c --- /dev/null +++ b/tests/unit/Serializers/PhpSerizalizerTest.php @@ -0,0 +1,30 @@ +assertEquals($expected, (new PhpSerializer())->getSerializedContentType()); + } + + public function test_serialize_retrunsProperValue() + { + $test = ['a', 'b', 'c']; + $expected = base64_encode(serialize($test)); + $this->assertEquals($expected, (new PhpSerializer())->serialize($test)); + } + + public function test_unserialize_retrunsProperValue() + { + $expected = ['a', 'b', 'c']; + $test = base64_encode(serialize($expected)); + $this->assertEquals($expected, (new PhpSerializer())->unserialize($test)); + } +} \ No newline at end of file