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

Commit a32a08a

Browse files
committed
Merge branch 'hotfix/39'
Close #39
2 parents 10e05f3 + d0bae5b commit a32a08a

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ All notable changes to this project will be documented in this file, in reverse
66

77
### Added
88

9-
- Nothing.
9+
- [#39](https://github.com/zendframework/zend-expressive-zendviewrenderer/pull/39)
10+
adds the ability for the `ZendViewRendererFactory` to use the
11+
`Zend\View\Renderer\PhpRenderer` service when present, defaulting to creating
12+
an unconfigured instance if none is available (previous behavior).
1013

1114
### Deprecated
1215

src/ZendViewRendererFactory.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,10 @@ public function __invoke(ContainerInterface $container)
6262
100
6363
);
6464

65-
// Create the renderer
66-
$renderer = new PhpRenderer();
65+
// Create or retrieve the renderer from the container
66+
$renderer = ($container->has(PhpRenderer::class))
67+
? $container->get(PhpRenderer::class)
68+
: new PhpRenderer();
6769
$renderer->setResolver($resolver);
6870

6971
// Inject helpers

test/ZendViewRendererFactoryTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Zend\Expressive\ZendView\ZendViewRendererFactory;
2121
use Zend\View\HelperPluginManager;
2222
use Zend\View\Model\ModelInterface;
23+
use Zend\View\Renderer\PhpRenderer;
2324
use Zend\View\Resolver\AggregateResolver;
2425
use Zend\View\Resolver\TemplateMapResolver;
2526

@@ -125,6 +126,7 @@ public function testCallingFactoryWithNoConfigReturnsZendViewInstance()
125126
{
126127
$this->container->has('config')->willReturn(false);
127128
$this->container->has(HelperPluginManager::class)->willReturn(false);
129+
$this->container->has(PhpRenderer::class)->willReturn(false);
128130
$this->injectBaseHelpers();
129131
$factory = new ZendViewRendererFactory();
130132
$view = $factory($this->container->reveal());
@@ -154,6 +156,7 @@ public function testConfiguresLayout()
154156
$this->container->has('config')->willReturn(true);
155157
$this->container->get('config')->willReturn($config);
156158
$this->container->has(HelperPluginManager::class)->willReturn(false);
159+
$this->container->has(PhpRenderer::class)->willReturn(false);
157160
$this->injectBaseHelpers();
158161
$factory = new ZendViewRendererFactory();
159162
$view = $factory($this->container->reveal());
@@ -175,6 +178,7 @@ public function testConfiguresPaths()
175178
$this->container->has('config')->willReturn(true);
176179
$this->container->get('config')->willReturn($config);
177180
$this->container->has(HelperPluginManager::class)->willReturn(false);
181+
$this->container->has(PhpRenderer::class)->willReturn(false);
178182
$this->injectBaseHelpers();
179183
$factory = new ZendViewRendererFactory();
180184
$view = $factory($this->container->reveal());
@@ -212,6 +216,7 @@ public function testConfiguresTemplateMap()
212216
$this->container->has('config')->willReturn(true);
213217
$this->container->get('config')->willReturn($config);
214218
$this->container->has(HelperPluginManager::class)->willReturn(false);
219+
$this->container->has(PhpRenderer::class)->willReturn(false);
215220
$this->injectBaseHelpers();
216221
$factory = new ZendViewRendererFactory();
217222
$view = $factory($this->container->reveal());
@@ -238,6 +243,7 @@ public function testInjectsCustomHelpersIntoHelperManager()
238243
{
239244
$this->container->has('config')->willReturn(false);
240245
$this->container->has(HelperPluginManager::class)->willReturn(false);
246+
$this->container->has(PhpRenderer::class)->willReturn(false);
241247
$this->injectBaseHelpers();
242248
$factory = new ZendViewRendererFactory();
243249
$view = $factory($this->container->reveal());
@@ -255,6 +261,7 @@ public function testInjectsCustomHelpersIntoHelperManager()
255261
public function testWillUseHelperManagerFromContainer()
256262
{
257263
$this->container->has('config')->willReturn(false);
264+
$this->container->has(PhpRenderer::class)->willReturn(false);
258265
$this->injectBaseHelpers();
259266

260267
$helpers = new HelperPluginManager($this->container->reveal());
@@ -281,4 +288,18 @@ public function testInjectsCustomHelpersIntoHelperManagerFromContainer(HelperPlu
281288
$this->assertInstanceOf(UrlHelper::class, $helpers->get('url'));
282289
$this->assertInstanceOf(ServerUrlHelper::class, $helpers->get('serverurl'));
283290
}
291+
292+
public function testWillUseRendererFromContainer()
293+
{
294+
$engine = new PhpRenderer;
295+
$this->container->has('config')->willReturn(false);
296+
$this->container->has(HelperPluginManager::class)->willReturn(false);
297+
$this->injectContainerService(PhpRenderer::class, $engine);
298+
299+
$factory = new ZendViewRendererFactory();
300+
$view = $factory($this->container->reveal());
301+
302+
$composed = $this->fetchPhpRenderer($view);
303+
$this->assertSame($engine, $composed);
304+
}
284305
}

0 commit comments

Comments
 (0)