Skip to content

Commit b15782d

Browse files
committed
MAGETWO-64465: Investigate and fix post-refactoring issues
1 parent 14a7222 commit b15782d

File tree

1 file changed

+22
-15
lines changed
  • app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Type

1 file changed

+22
-15
lines changed

app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Type/FileTest.php

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ protected function setUp()
7777

7878
$this->serializer = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class)
7979
->disableOriginalConstructor()
80+
->setMethods(['serialize', 'unserialize'])
8081
->getMock();
8182

8283
$this->urlBuilder = $this->getMockBuilder(\Magento\Catalog\Model\Product\Option\UrlBuilder::class)
@@ -99,6 +100,26 @@ protected function setUp()
99100
'',
100101
false
101102
);
103+
104+
$this->serializer->expects($this->any())
105+
->method('unserialize')
106+
->will(
107+
$this->returnCallback(
108+
function ($value) {
109+
return json_decode($value, true);
110+
}
111+
)
112+
);
113+
114+
$this->serializer->expects($this->any())
115+
->method('serialize')
116+
->will(
117+
$this->returnCallback(
118+
function ($value) {
119+
return json_encode($value);
120+
}
121+
)
122+
);
102123
}
103124

104125
/**
@@ -237,9 +258,6 @@ public function testGetFormattedOptionValue()
237258
public function testGetFormattedOptionValueInvalid()
238259
{
239260
$optionValue = 'invalid json option value...';
240-
$this->serializer->expects($this->once())
241-
->method('unserialize')
242-
->willThrowException(new SerializationException(__('Invalid JSON value.')));
243261
$this->assertEquals($optionValue, $this->getFileObject()->getFormattedOptionValue($optionValue));
244262
}
245263

@@ -361,25 +379,14 @@ public function testParseOptionValueInvalid()
361379
->method('create')
362380
->will($this->returnValue($itemMock));
363381

364-
$this->serializer->expects($this->once())
365-
->method('unserialize')
366-
->with($optionValue)
367-
->willThrowException(new SerializationException(__('Invalid JSON value.')));
368-
369382
$this->assertEquals(null, $fileObject->parseOptionValue($userInput, []));
370383
}
371384

372385
public function testPrepareOptionValueForRequest()
373386
{
374-
$optionValue = 'string';
375387
$resultValue = ['result'];
388+
$optionValue = json_encode($resultValue);
376389
$fileObject = $this->getFileObject();
377-
378-
$this->serializer->expects($this->once())
379-
->method('unserialize')
380-
->with($optionValue)
381-
->willReturn($resultValue);
382-
383390
$this->assertEquals($resultValue, $fileObject->prepareOptionValueForRequest($optionValue));
384391
}
385392
}

0 commit comments

Comments
 (0)