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

Commit 32b1a0a

Browse files
committed
Rename StreamFactory, and have it return a callable
The factory was originally intended to return a callable, and not the stream itself. As such, it needs to be renamed to `StreamFactoryFactory`, and wrap its return value in a closure. The IMPLICIT_HEAD_MIDDLEWARE_STREAM_FACTORY factory entry was updated to refer to the renamed class.
1 parent cc74dad commit 32b1a0a

File tree

5 files changed

+22
-20
lines changed

5 files changed

+22
-20
lines changed

phpunit.xml.dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
<testsuites>
77
<testsuite name="zend-expressive-response-factory">
88
<file>./test/Container/ResponseFactoryWithoutDiactorosTest.php</file>
9-
<file>./test/Container/StreamFactoryWithoutDiactorosTest.php</file>
9+
<file>./test/Container/StreamFactoryFactoryWithoutDiactorosTest.php</file>
1010
</testsuite>
1111
<testsuite name="zend-expressive">
1212
<directory>./test</directory>
1313
<exclude>./test/Container/ResponseFactoryWithoutDiactorosTest.php</exclude>
14-
<exclude>./test/Container/StreamFactoryWithoutDiactorosTest.php</exclude>
14+
<exclude>./test/Container/StreamFactoryFactoryWithoutDiactorosTest.php</exclude>
1515
</testsuite>
1616
</testsuites>
1717

src/ConfigProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function getDependencies() : array
5050
NOT_FOUND_RESPONSE => Container\ResponseFactory::class,
5151
RequestHandlerRunner::class => Container\RequestHandlerRunnerFactory::class,
5252
Router\IMPLICIT_HEAD_MIDDLEWARE_RESPONSE => Container\ResponseFactory::class,
53-
Router\IMPLICIT_HEAD_MIDDLEWARE_STREAM_FACTORY => Container\StreamFactory::class,
53+
Router\IMPLICIT_HEAD_MIDDLEWARE_STREAM_FACTORY => Container\StreamFactoryFactory::class,
5454
Router\IMPLICIT_OPTIONS_MIDDLEWARE_RESPONSE => Container\ResponseFactory::class,
5555
Router\METHOD_NOT_ALLOWED_MIDDLEWARE_RESPONSE => Container\ResponseFactory::class,
5656
SERVER_REQUEST_ERROR_RESPONSE_GENERATOR => Container\ServerRequestErrorResponseGeneratorFactory::class,

src/Container/StreamFactory.php renamed to src/Container/StreamFactoryFactory.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,15 @@
1010
namespace Zend\Expressive\Container;
1111

1212
use Psr\Container\ContainerInterface;
13-
use Psr\Http\Message\StreamInterface;
1413
use Zend\Diactoros\Stream;
1514

1615
/**
17-
* Produces an empty stream for use with services that need to produce a stream
18-
* for use with a request or a response. This service should be non-shared, if
19-
* your container supports that possibility, to ensure that the stream it
20-
* composes cannot be written to by any other consumer.
16+
* Produces a callable capable of producing an empty stream for use with
17+
* services that need to produce a stream for use with a request or a response.
2118
*/
22-
class StreamFactory
19+
class StreamFactoryFactory
2320
{
24-
public function __invoke(ContainerInterface $container) : StreamInterface
21+
public function __invoke(ContainerInterface $container) : callable
2522
{
2623
if (! class_exists(Stream::class)) {
2724
throw new Exception\InvalidServiceException(sprintf(
@@ -35,6 +32,8 @@ public function __invoke(ContainerInterface $container) : StreamInterface
3532
));
3633
}
3734

38-
return new Stream('php://temp', 'wb+');
35+
return function () : Stream {
36+
return new Stream('php://temp', 'wb+');
37+
};
3938
}
4039
}

test/Container/StreamFactoryTest.php renamed to test/Container/StreamFactoryFactoryTest.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,20 @@
1212
use PHPUnit\Framework\TestCase;
1313
use Psr\Container\ContainerInterface;
1414
use Zend\Diactoros\Stream;
15-
use Zend\Expressive\Container\StreamFactory;
15+
use Zend\Expressive\Container\StreamFactoryFactory;
1616

17-
class StreamFactoryTest extends TestCase
17+
class StreamFactoryFactoryTest extends TestCase
1818
{
19-
public function testFactoryProducesAStreamWhenDiactorosIsInstalled()
19+
public function testFactoryProducesACallableCapableOfGeneratingAStreamWhenDiactorosIsInstalled()
2020
{
2121
$container = $this->prophesize(ContainerInterface::class)->reveal();
22-
$factory = new StreamFactory();
22+
$factory = new StreamFactoryFactory();
2323

24-
$response = $factory($container);
24+
$result = $factory($container);
2525

26-
$this->assertInstanceOf(Stream::class, $response);
26+
$this->assertInternalType('callable', $result);
27+
28+
$stream = $result();
29+
$this->assertInstanceOf(Stream::class, $stream);
2730
}
2831
}

test/Container/StreamFactoryWithoutDiactorosTest.php renamed to test/Container/StreamFactoryFactoryWithoutDiactorosTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
use Psr\Container\ContainerInterface;
1414
use Throwable;
1515
use Zend\Expressive\Container\Exception\InvalidServiceException;
16-
use Zend\Expressive\Container\StreamFactory;
16+
use Zend\Expressive\Container\StreamFactoryFactory;
1717

18-
class StreamFactoryWithoutDiactorosTest extends TestCase
18+
class StreamFactoryFactoryWithoutDiactorosTest extends TestCase
1919
{
2020
private $autoloadFunctions = [];
2121

@@ -24,7 +24,7 @@ public function setUp()
2424
class_exists(InvalidServiceException::class);
2525

2626
$this->container = $this->prophesize(ContainerInterface::class)->reveal();
27-
$this->factory = new StreamFactory();
27+
$this->factory = new StreamFactoryFactory();
2828

2929
foreach (spl_autoload_functions() as $autoloader) {
3030
if (! is_array($autoloader)) {

0 commit comments

Comments
 (0)