Skip to content

Commit 8959beb

Browse files
author
Yuri Kovsher
committed
MAGETWO-34920: Catch all exceptions inside of Phrase::__toString() method and log messages
1 parent cc6ec2b commit 8959beb

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

lib/internal/Magento/Framework/Phrase.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ public function render()
103103
*/
104104
public function __toString()
105105
{
106-
return $this->render();
106+
try {
107+
return $this->render();
108+
} catch (\Exception $e) {
109+
return $this->getText();
110+
}
107111
}
108112

109113
/**

lib/internal/Magento/Framework/Test/Unit/PhraseTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
namespace Magento\Framework\Test\Unit;
77

8-
use \Magento\Framework\Phrase;
8+
use Magento\Framework\Phrase;
99

1010
class PhraseTest extends \PHPUnit_Framework_TestCase
1111
{
@@ -124,4 +124,17 @@ public function testGetArguments()
124124
$this->assertEquals([], $phrase1->getArguments());
125125
$this->assertEquals($arguments, $phrase2->getArguments());
126126
}
127+
128+
public function testToStringWithExceptionOnRender()
129+
{
130+
$text = 'raw text';
131+
$exception = new \Exception('something went wrong');
132+
$phrase = new Phrase($text);
133+
134+
$this->rendererMock->expects($this->any())
135+
->method('render')
136+
->willThrowException($exception);
137+
138+
$this->assertEquals($text, (string)$phrase);
139+
}
127140
}

0 commit comments

Comments
 (0)