Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 7fa3a73

Browse files
committed
Compose an EmitterStack by default
- It makes sense to compose an EmitterStack by default; that way, users of AppFactory can manipulate the emitter without needing to resort to direct instantiation.
1 parent 69eadac commit 7fa3a73

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/Application.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,15 +458,16 @@ public function getFinalHandler(ResponseInterface $response = null)
458458
/**
459459
* Retrieve an emitter to use during run().
460460
*
461-
* If none was registered during instantiation, this will lazy-load a
462-
* SapiEmitter instance.
461+
* If none was registered during instantiation, this will lazy-load an
462+
* EmitterStack composing an SapiEmitter instance.
463463
*
464464
* @return EmitterInterface
465465
*/
466466
public function getEmitter()
467467
{
468468
if (! $this->emitter) {
469-
$this->emitter = new SapiEmitter;
469+
$this->emitter = new Emitter\EmitterStack();
470+
$this->emitter->push(new SapiEmitter());
470471
}
471472
return $this->emitter;
472473
}

test/ApplicationTest.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
use PHPUnit_Framework_TestCase as TestCase;
1414
use Prophecy\Argument;
1515
use ReflectionProperty;
16+
use Zend\Diactoros\Response\SapiEmitter;
1617
use Zend\Diactoros\ServerRequest as Request;
1718
use Zend\Expressive\Application;
19+
use Zend\Expressive\Emitter\EmitterStack;
1820
use Zend\Expressive\Router\Route;
1921
use Zend\Expressive\Router\RouteResult;
2022
use Zend\Stratigility\Route as StratigilityRoute;
@@ -260,11 +262,15 @@ public function testFinalHandlerIsUsedAtInvocationIfNoOutArgumentIsSupplied()
260262
$this->assertSame($finalResponse, $test);
261263
}
262264

263-
public function testComposesSapiEmitterByDefault()
265+
public function testComposesEmitterStackWithSapiEmitterByDefault()
264266
{
265-
$app = $this->getApp();
266-
$emitter = $app->getEmitter();
267-
$this->assertInstanceOf('Zend\Diactoros\Response\SapiEmitter', $emitter);
267+
$app = $this->getApp();
268+
$stack = $app->getEmitter();
269+
$this->assertInstanceOf(EmitterStack::class, $stack);
270+
271+
$this->assertCount(1, $stack);
272+
$test = $stack->pop();
273+
$this->assertInstanceOf(SapiEmitter::class, $test);
268274
}
269275

270276
public function testAllowsInjectingEmitterAtInstantiation()

0 commit comments

Comments
 (0)