Skip to content

Commit 3311cf4

Browse files
author
Mykola Palamar
committed
MAGETWO-66100: Remove usages of unserialize in module Magento/Setup
1 parent 239efc3 commit 3311cf4

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

setup/src/Magento/Setup/Model/AdminAccountFactory.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use Magento\Setup\Module\Setup;
1010
use Zend\ServiceManager\ServiceLocatorInterface;
11+
use Magento\Framework\Serialize\Serializer\Json;
1112

1213
class AdminAccountFactory
1314
{
@@ -34,7 +35,8 @@ public function create(Setup $setup, $data)
3435
return new AdminAccount(
3536
$setup,
3637
$this->serviceLocator->get(\Magento\Framework\Encryption\Encryptor::class),
37-
$data
38+
$data,
39+
new Json()
3840
);
3941
}
4042
}

setup/src/Magento/Setup/Test/Unit/Model/AdminAccountTest.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Setup\Test\Unit\Model;
88

99
use \Magento\Setup\Model\AdminAccount;
10+
use Magento\Framework\Serialize\Serializer\Json;
1011

1112
class AdminAccountTest extends \PHPUnit_Framework_TestCase
1213
{
@@ -30,6 +31,11 @@ class AdminAccountTest extends \PHPUnit_Framework_TestCase
3031
*/
3132
private $adminAccount;
3233

34+
/**
35+
* @var Json|\PHPUnit_Framework_MockObject_MockObject
36+
*/
37+
private $serializer;
38+
3339
public function setUp()
3440
{
3541
$this->setUpMock = $this->getMock(\Magento\Setup\Module\Setup::class, [], [], '', false);
@@ -53,6 +59,12 @@ function ($table) {
5359
$this->encryptor = $this->getMockBuilder(\Magento\Framework\Encryption\EncryptorInterface::class)
5460
->getMockForAbstractClass();
5561

62+
$this->serializer = $this->getMockBuilder(Json::class)
63+
->getMock();
64+
$this->serializer->expects($this->any())->method('serialize')->willReturnCallback(function ($param) {
65+
return json_encode($param);
66+
});
67+
5668
$data = [
5769
AdminAccount::KEY_FIRST_NAME => 'John',
5870
AdminAccount::KEY_LAST_NAME => 'Doe',
@@ -61,7 +73,12 @@ function ($table) {
6173
AdminAccount::KEY_USER => 'admin',
6274
];
6375

64-
$this->adminAccount = new AdminAccount($this->setUpMock, $this->encryptor, $data);
76+
$this->adminAccount = new AdminAccount(
77+
$this->setUpMock,
78+
$this->encryptor,
79+
$data,
80+
$this->serializer
81+
);
6582
}
6683

6784
public function testSaveUserExistsAdminRoleExists()

0 commit comments

Comments
 (0)