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

Commit 1af2aeb

Browse files
committed
Merge branch 'hotfix/111'
Close #111
2 parents d2ce696 + 409bb97 commit 1af2aeb

File tree

3 files changed

+88
-4
lines changed

3 files changed

+88
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
All notable changes to this project will be documented in this file, in reverse chronological order by release.
44

5-
## 2.7.5 - TBD
5+
## 2.7.5 - 2016-04-06
66

77
### Added
88

@@ -18,7 +18,10 @@ All notable changes to this project will be documented in this file, in reverse
1818

1919
### Fixed
2020

21-
- Nothing.
21+
- [#111](https://github.com/zendframework/zend-mvc/pull/111) fixes a bug in how
22+
the `ConsoleExceptionStrategyFactory` whereby it was overwriting the default
23+
exception message template with an empty string when no configuration for it
24+
was provided.
2225

2326
## 2.7.4 - 2016-04-03
2427

src/Service/ConsoleExceptionStrategyFactory.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ private function injectDisplayExceptions(ExceptionStrategy $strategy, array $con
6868
*/
6969
private function injectExceptionMessage(ExceptionStrategy $strategy, array $config)
7070
{
71-
$message = isset($config['exception_message']) ? $config['exception_message'] : '';
72-
$strategy->setMessage($message);
71+
if (isset($config['exception_message'])) {
72+
$strategy->setMessage($config['exception_message']);
73+
}
7374
}
7475
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
/**
3+
* Zend Framework (http://framework.zend.com/)
4+
*
5+
* @link http://github.com/zendframework/zf2 for the canonical source repository
6+
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
7+
* @license http://framework.zend.com/license/new-bsd New BSD License
8+
*/
9+
10+
namespace ZendTest\Mvc\Service;
11+
12+
use Interop\Container\ContainerInterface;
13+
use PHPUnit_Framework_TestCase as TestCase;
14+
use Zend\Mvc\Service\ConsoleExceptionStrategyFactory;
15+
use Zend\Mvc\View\Console\ExceptionStrategy;
16+
17+
class ConsoleExceptionStrategyFactoryTest extends TestCase
18+
{
19+
public function createContainer($config = [])
20+
{
21+
$container = $this->prophesize(ContainerInterface::class);
22+
$container->has('config')->willReturn(true);
23+
$container->get('config')->willReturn($config);
24+
return $container->reveal();
25+
}
26+
27+
public function testReturnsExceptionStrategy()
28+
{
29+
$factory = new ConsoleExceptionStrategyFactory();
30+
$result = $factory($this->createContainer(), 'ConsoleExceptionStrategy');
31+
$this->assertInstanceOf(ExceptionStrategy::class, $result);
32+
}
33+
34+
public function testIfNotSetShouldUseDefaultExceptionMessageTemplate()
35+
{
36+
$factory = new ConsoleExceptionStrategyFactory();
37+
$result = $factory($this->createContainer(), 'ConsoleExceptionStrategy');
38+
39+
$strategy = new ExceptionStrategy();
40+
$this->assertEquals($strategy->getMessage(), $result->getMessage());
41+
}
42+
43+
public function testExceptionMessageTemplateCanBeChangedInConfig()
44+
{
45+
$config = [
46+
'console' => [
47+
'view_manager' => [
48+
'exception_message' => 'Custom template :className :message',
49+
]
50+
]
51+
];
52+
$factory = new ConsoleExceptionStrategyFactory();
53+
$result = $factory($this->createContainer($config), 'ConsoleExceptionStrategy');
54+
55+
$this->assertEquals($config['console']['view_manager']['exception_message'], $result->getMessage());
56+
}
57+
58+
public function testDisplayExceptionsEnabledByDefault()
59+
{
60+
$factory = new ConsoleExceptionStrategyFactory();
61+
$result = $factory($this->createContainer(), 'ConsoleExceptionStrategy');
62+
63+
$this->assertTrue($result->displayExceptions(), 'displayExceptions should be enabled by default.');
64+
}
65+
66+
public function testDisplayExceptionsCanBeChangedInConfig()
67+
{
68+
$config = [
69+
'console' => [
70+
'view_manager' => [
71+
'display_exceptions' => false,
72+
]
73+
]
74+
];
75+
$factory = new ConsoleExceptionStrategyFactory();
76+
$result = $factory($this->createContainer($config), 'ConsoleExceptionStrategy');
77+
78+
$this->assertFalse($result->displayExceptions(), 'displayExceptions should be disabled in config.');
79+
}
80+
}

0 commit comments

Comments
 (0)