-
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.
- Loading branch information
Marco Perone
committed
Apr 10, 2017
1 parent
585946c
commit e854dc4
Showing
2 changed files
with
56 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,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Marcosh\Effector\Effect\Http; | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
use Zend\Diactoros\Response\EmitterInterface; | ||
use Zend\Diactoros\Response\SapiEmitter; | ||
|
||
final class EmitResponse | ||
{ | ||
/** | ||
* @var EmitterInterface|null | ||
*/ | ||
private $emitter; | ||
|
||
public function __construct(?EmitterInterface $emitter = null) | ||
{ | ||
if (null === $emitter) { | ||
$emitter = new SapiEmitter(); | ||
} | ||
|
||
$this->emitter = $emitter; | ||
} | ||
|
||
public function __invoke(ResponseInterface $response): void | ||
{ | ||
$this->emitter->emit($response); | ||
} | ||
} |
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,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Marcosh\EffectorTest\Effect\Http; | ||
|
||
use Marcosh\Effector\Effect\Http\EmitResponse; | ||
use PHPUnit\Framework\TestCase; | ||
use Zend\Diactoros\Response; | ||
use Zend\Diactoros\Response\EmitterInterface; | ||
|
||
final class EmitResponseTest extends TestCase | ||
{ | ||
public function testEmitsResponseCorrectly() | ||
{ | ||
$emitter = \Mockery::spy(EmitterInterface::class); | ||
|
||
$emitResponse = new EmitResponse($emitter); | ||
$response = new Response(); | ||
|
||
$emitResponse($response); | ||
|
||
$emitter->shouldHaveReceived('emit')->with($response); | ||
} | ||
} |