Skip to content

Commit 7bf469a

Browse files
committed
MAGETWO-62510: Remove uses of serialize/unserialize in \Magento\Ui\Model\Manager
1 parent 126f95c commit 7bf469a

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

app/code/Magento/Ui/Model/Manager.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Magento\Framework\View\Element\UiComponent\Config\ReaderFactory;
1919
use Magento\Framework\View\Element\UiComponent\Config\UiReaderInterface;
2020
use Magento\Framework\Serialize\SerializerInterface;
21+
use Magento\Framework\App\ObjectManager;
2122

2223
/**
2324
* Class Manager
@@ -108,7 +109,7 @@ class Manager implements ManagerInterface
108109
* @param AggregatedFileCollectorFactory $aggregatedFileCollectorFactory
109110
* @param CacheInterface $cache
110111
* @param InterpreterInterface $argumentInterpreter
111-
* @param SerializerInterface $serializer
112+
* @param SerializerInterface|null $serializer
112113
*/
113114
public function __construct(
114115
ComponentDefinition $componentConfigProvider,
@@ -118,7 +119,7 @@ public function __construct(
118119
AggregatedFileCollectorFactory $aggregatedFileCollectorFactory,
119120
CacheInterface $cache,
120121
InterpreterInterface $argumentInterpreter,
121-
SerializerInterface $serializer
122+
SerializerInterface $serializer = null
122123

123124
) {
124125
$this->componentConfigProvider = $componentConfigProvider;
@@ -129,7 +130,7 @@ public function __construct(
129130
$this->aggregatedFileCollectorFactory = $aggregatedFileCollectorFactory;
130131
$this->cache = $cache;
131132
$this->argumentInterpreter = $argumentInterpreter;
132-
$this->serializer = $serializer;
133+
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class);
133134
}
134135

135136
/**

app/code/Magento/Ui/Test/Unit/Model/ManagerTest.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ class ManagerTest extends \PHPUnit_Framework_TestCase
7575
*/
7676
protected $aggregatedFileCollectorFactory;
7777

78+
/** @var \Magento\Framework\Serialize\SerializerInterface|\PHPUnit_Framework_MockObject_MockObject */
79+
private $serializer;
80+
7881
protected function setUp()
7982
{
8083
$this->componentConfigProvider = $this->getMockBuilder(
@@ -105,14 +108,33 @@ protected function setUp()
105108
->getMockForAbstractClass();
106109
$this->argumentInterpreter = $this->getMockBuilder(\Magento\Framework\Data\Argument\InterpreterInterface::class)
107110
->getMockForAbstractClass();
111+
$this->serializer = $this->getMockBuilder(
112+
\Magento\Framework\Serialize\SerializerInterface::class
113+
)->getMockForAbstractClass();
114+
$this->serializer->expects($this->any())
115+
->method('serialize')
116+
->willReturnCallback(
117+
function ($value) {
118+
return json_encode($value);
119+
}
120+
);
121+
$this->serializer->expects($this->any())
122+
->method('unserialize')
123+
->willReturnCallback(
124+
function ($value) {
125+
return json_decode($value, true);
126+
}
127+
);
128+
108129
$this->manager = new Manager(
109130
$this->componentConfigProvider,
110131
$this->domMerger,
111132
$this->readerFactory,
112133
$this->arrayObjectFactory,
113134
$this->aggregatedFileCollectorFactory,
114135
$this->cacheConfig,
115-
$this->argumentInterpreter
136+
$this->argumentInterpreter,
137+
$this->serializer
116138
);
117139
}
118140

@@ -192,7 +214,7 @@ public function getComponentData()
192214
[
193215
'test_component1',
194216
new \ArrayObject(),
195-
$cachedData->serialize(),
217+
json_encode($cachedData->getArrayCopy()),
196218
[],
197219
[
198220
'test_component1' => [

0 commit comments

Comments
 (0)