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

Commit 7e2cfe8

Browse files
committed
Merge pull request #111 from svycka/patch-2
use default console exception template instead of empty string
2 parents d2ce696 + 8c5b750 commit 7e2cfe8

File tree

2 files changed

+83
-2
lines changed

2 files changed

+83
-2
lines changed

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)