Skip to content

Commit

Permalink
emit response effect
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Perone committed Apr 10, 2017
1 parent 585946c commit e854dc4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/Effect/Http/EmitResponse.php
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);
}
}
25 changes: 25 additions & 0 deletions test/Effect/Http/EmitResponseTest.php
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);
}
}

0 comments on commit e854dc4

Please sign in to comment.