From d6e4f32ec8b93a7c6902237c2ec6e3d5e95984eb Mon Sep 17 00:00:00 2001 From: Marcos Zuriaga Date: Sun, 9 Oct 2016 18:24:14 +0200 Subject: [PATCH] Added EntityJSONSerializer trait unit tests --- .../unit/lib/Db/EntityJSONSerializerTest.php | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tests/unit/lib/Db/EntityJSONSerializerTest.php diff --git a/tests/unit/lib/Db/EntityJSONSerializerTest.php b/tests/unit/lib/Db/EntityJSONSerializerTest.php new file mode 100644 index 00000000..d918dfbd --- /dev/null +++ b/tests/unit/lib/Db/EntityJSONSerializerTest.php @@ -0,0 +1,50 @@ + 'value', + 'an_int' => 1234, + 'a_bool' => true, + 'null' => null, + 'a_double' => 4.563, + 'an_int_array' => [1, 32, 55, 134], + 'an_string_array' => ['asdf', 'fdsa'] + ]; + + /** + * @var EntityJSONSerializer + */ + protected $trait; + + public function setUp() { + $this->trait = $this->getObjectForTrait(EntityJSONSerializer::class); + + foreach (self::TEST_FIELDS as $key => $value){ + $this->trait->$key = $value; + } + } + + public function testSerializeFieldsFull(){ + $actual_data = $this->trait->serializeFields(array_keys(self::TEST_FIELDS)); + $this->assertEquals(self::TEST_FIELDS, $actual_data); + } + + public function testSerializeFieldsPartial(){ + $fields = ['an_string', 'an_int', 'an_int_array']; + $actual_data = $this->trait->serializeFields($fields); + $expected_data = []; + foreach ($fields as $value){ + $expected_data[$value] = self::TEST_FIELDS[$value]; + } + $this->assertEquals($expected_data, $actual_data); + } +} \ No newline at end of file