Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kachit committed Feb 29, 2016
1 parent 27ad10b commit 16b59d0
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/Kachit/Helper/Tests/Json/DecoderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* Json decoder test
*
* @author Kachit
* @package Kachit\Helper\Tests
*/
namespace Kachit\Helper\Tests\Json;

use Kachit\Helper\Json\Decoder;

class DecoderTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Decoder
*/
private $testable;

/**
* Init
*/
protected function setUp()
{
$this->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);
}
}
45 changes: 45 additions & 0 deletions tests/Kachit/Helper/Tests/Json/EncoderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* Json decoder test
*
* @author Kachit
* @package Kachit\Helper\Tests
*/
namespace Kachit\Helper\Tests\Json;

use Kachit\Helper\Json\Encoder;

class EncoderTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Encoder
*/
private $testable;

/**
* Init
*/
protected function setUp()
{
$this->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);
}
}

0 comments on commit 16b59d0

Please sign in to comment.