Skip to content

Commit 06f748b

Browse files
committed
MAGETWO-66686: Use Json serializer class instead of direct call
- fixing tests
1 parent 4df814d commit 06f748b

File tree

5 files changed

+32
-6
lines changed

5 files changed

+32
-6
lines changed

app/code/Magento/Backend/Model/Url.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Backend\Model;
77

8+
use Magento\Framework\Serialize\Serializer\Json;
89
use Magento\Framework\Url\HostChecker;
910
use Magento\Framework\App\ObjectManager;
1011

@@ -101,6 +102,7 @@ class Url extends \Magento\Framework\Url implements \Magento\Backend\Model\UrlIn
101102
* @param \Magento\Framework\Data\Form\FormKey $formKey
102103
* @param array $data
103104
* @param HostChecker|null $hostChecker
105+
* @param Json $serializer
104106
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
105107
*/
106108
public function __construct(
@@ -123,7 +125,8 @@ public function __construct(
123125
\Magento\Store\Model\StoreFactory $storeFactory,
124126
\Magento\Framework\Data\Form\FormKey $formKey,
125127
array $data = [],
126-
HostChecker $hostChecker = null
128+
HostChecker $hostChecker = null,
129+
Json $serializer = null
127130
) {
128131
$this->_encryptor = $encryptor;
129132
$hostChecker = $hostChecker ?: ObjectManager::getInstance()->get(HostChecker::class);
@@ -140,7 +143,8 @@ public function __construct(
140143
$routeParamsPreprocessor,
141144
$scopeType,
142145
$data,
143-
$hostChecker
146+
$hostChecker,
147+
$serializer
144148
);
145149
$this->_backendHelper = $backendHelper;
146150
$this->_menuConfig = $menuConfig;

app/code/Magento/Backend/Test/Unit/Model/UrlTest.php

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

8+
use Magento\Framework\Serialize\Serializer\Json;
89
use Magento\Framework\Url\HostChecker;
910

1011
/**
@@ -68,6 +69,11 @@ class UrlTest extends \PHPUnit_Framework_TestCase
6869
*/
6970
protected $_encryptor;
7071

72+
/**
73+
* @var Json|\PHPUnit_Framework_MockObject_MockObject
74+
*/
75+
private $serializerMock;
76+
7177
/**
7278
* @return void
7379
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
@@ -151,6 +157,20 @@ protected function setUp()
151157
->willReturn($routeParamsResolver);
152158
/** @var HostChecker|\PHPUnit_Framework_MockObject_MockObject $hostCheckerMock */
153159
$hostCheckerMock = $this->getMock(HostChecker::class, [], [], '', false);
160+
$this->serializerMock = $this->getMockBuilder(Json::class)
161+
->setMethods(['serialize'])
162+
->disableOriginalConstructor()
163+
->getMock();
164+
165+
$this->serializerMock->expects($this->any())
166+
->method('serialize')
167+
->will(
168+
$this->returnCallback(
169+
function ($value) {
170+
return json_encode($value);
171+
}
172+
)
173+
);
154174
$this->_model = $objectManager->getObject(
155175
\Magento\Backend\Model\Url::class,
156176
[
@@ -161,7 +181,8 @@ protected function setUp()
161181
'authSession' => $this->_authSessionMock,
162182
'encryptor' => $this->_encryptor,
163183
'routeParamsResolverFactory' => $this->routeParamsResolverFactoryMock,
164-
'hostChecker' => $hostCheckerMock
184+
'hostChecker' => $hostCheckerMock,
185+
'serializer' => $this->serializerMock
165186
]
166187
);
167188
$this->_requestMock = $this->getMock(\Magento\Framework\App\Request\Http::class, [], [], '', false);

app/code/Magento/Catalog/Test/Unit/Block/Rss/CategoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ protected function setUp()
9595
$this->request->expects($this->at(0))->method('getParam')->with('cid')->will($this->returnValue(1));
9696
$this->request->expects($this->at(1))->method('getParam')->with('store_id')->will($this->returnValue(null));
9797

98-
$this->httpContext = $this->getMock(\Magento\Framework\App\Http\Context::class);
98+
$this->httpContext = $this->getMock(\Magento\Framework\App\Http\Context::class, [], [], '', false);
9999
$this->catalogHelper = $this->getMock(\Magento\Catalog\Helper\Data::class, [], [], '', false);
100100
$this->categoryFactory = $this->getMockBuilder(\Magento\Catalog\Model\CategoryFactory::class)
101101
->setMethods(['create'])

app/code/Magento/CatalogWidget/Test/Unit/Block/Product/ProductsListTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ protected function setUp()
9393
->setMethods(['getVisibleInCatalogIds'])
9494
->disableOriginalConstructor()
9595
->getMock();
96-
$this->httpContext = $this->getMock(\Magento\Framework\App\Http\Context::class);
96+
$this->httpContext = $this->getMock(\Magento\Framework\App\Http\Context::class, [], [], '', false);
9797
$this->builder = $this->getMock(\Magento\Rule\Model\Condition\Sql\Builder::class, [], [], '', false);
9898
$this->rule = $this->getMock(\Magento\CatalogWidget\Model\Rule::class, [], [], '', false);
9999
$this->serializer = $this->getMock(\Magento\Framework\Serialize\Serializer\Json::class, [], [], '', false);

dev/tests/static/framework/bootstrap.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
$componentRegistrar = new ComponentRegistrar();
2020
$dirSearch = new DirSearch($componentRegistrar, new ReadFactory(new DriverPool()));
2121
$themePackageList = new ThemePackageList($componentRegistrar, new ThemePackageFactory());
22+
$serializer = new \Magento\Framework\Serialize\Serializer\Json();
2223
\Magento\Framework\App\Utility\Files::setInstance(
23-
new Files($componentRegistrar, $dirSearch, $themePackageList)
24+
new Files($componentRegistrar, $dirSearch, $themePackageList, $serializer)
2425
);
2526

2627
/**

0 commit comments

Comments
 (0)