forked from slashtrace/slashtrace
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request slashtrace#6 from slashtrace/feature/json-renderer
Feature - JSON renderer
- Loading branch information
Showing
17 changed files
with
388 additions
and
18 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
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
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
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
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
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,21 @@ | ||
<?php | ||
|
||
namespace SlashTrace\DebugRenderer; | ||
|
||
use SlashTrace\Event; | ||
use SlashTrace\System\HasSystemProvider; | ||
|
||
class DebugJsonRenderer implements DebugRenderer | ||
{ | ||
use HasSystemProvider; | ||
|
||
public function render(Event $event) | ||
{ | ||
$this->getSystem()->output( | ||
json_encode(array_merge( | ||
["success" => false], | ||
$event->jsonSerialize() | ||
)) | ||
); | ||
} | ||
} |
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
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
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
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
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
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
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,46 @@ | ||
<?php | ||
|
||
namespace SlashTrace\Tests\DebugRenderer; | ||
|
||
use SlashTrace\DebugRenderer\DebugJsonRenderer; | ||
use SlashTrace\Event; | ||
use SlashTrace\Tests\Doubles\System\MockSystemProvider; | ||
use SlashTrace\Tests\TestCase; | ||
|
||
class DebugJsonRendererTest extends TestCase | ||
{ | ||
/** @var DebugJsonRenderer */ | ||
private $renderer; | ||
|
||
/** @var MockSystemProvider */ | ||
private $system; | ||
|
||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->system = new MockSystemProvider(); | ||
|
||
$this->renderer = new DebugJsonRenderer(); | ||
$this->renderer->setSystem($this->system); | ||
} | ||
|
||
public function testOutput() | ||
{ | ||
$event = $this->createMock(Event::class); | ||
$event->expects($this->once()) | ||
->method("jsonSerialize") | ||
->willReturn(["foo" => "bar"]); | ||
|
||
/** @noinspection PhpParamsInspection */ | ||
$this->renderer->render($event); | ||
|
||
$this->assertEquals( | ||
json_encode([ | ||
"success" => false, | ||
"foo" => "bar", | ||
]), | ||
$this->system->getOutput()[0] | ||
); | ||
} | ||
} |
Oops, something went wrong.