created mocks for testing

This commit is contained in:
Guillermo Dev
2018-10-13 18:00:51 +02:00
parent e53debb98d
commit 1211af09cc
26 changed files with 412 additions and 118 deletions

View File

@@ -1,17 +1,34 @@
<?php
namespace BSR\Webservice\Formatter;
class Json extends Formatter {
protected static function init() {
self::registerFormats(array(
'application/json',
'application/x-json',
));
use PHPUnit\Framework\TestCase;
class JsonTest extends TestCase
{
protected $accept = array(
'application/json',
'application/x-json',
);
public function testRenderEncodesDataIntoJsonFormat()
{
$format = new Json();
$someArray = array(
'asdf' => array(1, 'a', 'b', array()),
'1' => array(3 => 'c'),
0 => 'hello',
);
ob_start();
$format->render($someArray);
$jsonRepresentation = ob_get_clean();
$this->assertSame(json_decode($jsonRepresentation, true), $someArray);
}
public function render($data) {
echo json_encode($data);
public function testRegistersItsFormatAcceptHeader()
{
Formatter::getFormatter();
$formats = Formatter::getRegisterdFormats();
$this->assertSame(array_intersect($this->accept, array_keys($formats)), $this->accept);
}
}