9
9
use Magento \Framework \Model \Context ;
10
10
use Magento \Framework \Serialize \Serializer \Json ;
11
11
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
12
+ use Psr \Log \LoggerInterface ;
12
13
14
+ /**
15
+ * Class SerializedTest
16
+ */
13
17
class SerializedTest extends \PHPUnit \Framework \TestCase
14
18
{
15
19
/** @var \Magento\Config\Model\Config\Backend\Serialized */
@@ -18,14 +22,20 @@ class SerializedTest extends \PHPUnit\Framework\TestCase
18
22
/** @var Json|\PHPUnit_Framework_MockObject_MockObject */
19
23
private $ serializerMock ;
20
24
25
+ /** @var LoggerInterface|\PHPUnit_Framework_MockObject_MockObject */
26
+ private $ loggerMock ;
27
+
21
28
protected function setUp ()
22
29
{
23
30
$ objectManager = new ObjectManager ($ this );
24
31
$ this ->serializerMock = $ this ->createMock (Json::class);
32
+ $ this ->loggerMock = $ this ->createMock (LoggerInterface::class);
25
33
$ contextMock = $ this ->createMock (Context::class);
26
34
$ eventManagerMock = $ this ->createMock (\Magento \Framework \Event \ManagerInterface::class);
27
35
$ contextMock ->method ('getEventDispatcher ' )
28
36
->willReturn ($ eventManagerMock );
37
+ $ contextMock ->method ('getLogger ' )
38
+ ->willReturn ($ this ->loggerMock );
29
39
$ this ->serializedConfig = $ objectManager ->getObject (
30
40
Serialized::class,
31
41
[
@@ -72,6 +82,20 @@ public function afterLoadDataProvider()
72
82
];
73
83
}
74
84
85
+ public function testAfterLoadWithException ()
86
+ {
87
+ $ value = '{"key": ' ;
88
+ $ expected = false ;
89
+ $ this ->serializedConfig ->setValue ($ value );
90
+ $ this ->serializerMock ->expects ($ this ->once ())
91
+ ->method ('unserialize ' )
92
+ ->willThrowException (new \Exception ());
93
+ $ this ->loggerMock ->expects ($ this ->once ())
94
+ ->method ('critical ' );
95
+ $ this ->serializedConfig ->afterLoad ();
96
+ $ this ->assertEquals ($ expected , $ this ->serializedConfig ->getValue ());
97
+ }
98
+
75
99
/**
76
100
* @param string $expected
77
101
* @param int|double|string|array|boolean|null $value
0 commit comments