-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |