From 16b59d0c489b465f887ef56d83d93877687eb8e1 Mon Sep 17 00:00:00 2001 From: Kachit Date: Mon, 29 Feb 2016 23:23:22 +0300 Subject: [PATCH] add more tests --- .../Kachit/Helper/Tests/Json/DecoderTest.php | 42 +++++++++++++++++ .../Kachit/Helper/Tests/Json/EncoderTest.php | 45 +++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 tests/Kachit/Helper/Tests/Json/DecoderTest.php create mode 100644 tests/Kachit/Helper/Tests/Json/EncoderTest.php diff --git a/tests/Kachit/Helper/Tests/Json/DecoderTest.php b/tests/Kachit/Helper/Tests/Json/DecoderTest.php new file mode 100644 index 0000000..6fc445f --- /dev/null +++ b/tests/Kachit/Helper/Tests/Json/DecoderTest.php @@ -0,0 +1,42 @@ +testable = new Decoder(); + } + + public function testDecodeByDefault() + { + $expected = ['foo' => 123, 'bar' => 456, 'fi' => []]; + $json = json_encode($expected); + $actual = $this->testable->decode($json); + $this->assertEquals($expected, $actual); + } + + public function testDecodeAsObject() + { + $expected = ['foo' => 123, 'bar' => 456, 'fi' => []]; + $json = json_encode($expected); + $actual = $this->testable->setDecodeAsObject()->decode($json); + $this->assertEquals((object)$expected, $actual); + } +} diff --git a/tests/Kachit/Helper/Tests/Json/EncoderTest.php b/tests/Kachit/Helper/Tests/Json/EncoderTest.php new file mode 100644 index 0000000..7823b41 --- /dev/null +++ b/tests/Kachit/Helper/Tests/Json/EncoderTest.php @@ -0,0 +1,45 @@ +testable = new Encoder(); + } + + public function testEncodeByDefault() + { + $optionsEncode = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE; + $data = ['foo' => 123, 'bar' => 456, 'fi' => []]; + $jsonExpected = json_encode($data, $optionsEncode); + $jsonActual = $this->testable->encode($data); + $this->assertEquals($jsonExpected, $jsonActual); + } + + public function testEncodeWithPrettyPrint() + { + $optionsEncode = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT; + $data = ['foo' => 123, 'bar' => 456, 'fi' => []]; + $jsonExpected = json_encode($data, $optionsEncode); + $this->testable->enablePrettyPrint(); + $jsonActual = $this->testable->encode($data); + $this->assertEquals($jsonExpected, $jsonActual); + } +}