18 private $serializeMock;
28 private $serializedDataConverter;
33 $this->serializeMock = $this->createMock(Serialize::class);
34 $this->jsonMock = $this->createMock(Json::class);
36 SerializedDataConverter::class,
38 'serialize' => $this->serializeMock,
39 'json' => $this->jsonMock
46 $serializedData =
'serialized data';
47 $jsonEncodedData =
'json encoded data';
49 'info_buyRequest' => [
54 $this->serializeMock->expects($this->once())
55 ->method(
'unserialize')
56 ->with($serializedData)
58 $this->jsonMock->expects($this->once())
61 ->willReturn($jsonEncodedData);
64 $this->serializedDataConverter->convert($serializedData)
70 $serializedData =
'serialized data';
71 $serializedBundleAttributes =
'serialized bundle attributes';
72 $bundleAttributes = [
'foo' =>
'bar'];
73 $jsonEncodedBundleAttributes =
'json encoded bundle attributes';
74 $jsonEncodedData =
'json encoded data';
76 'info_buyRequest' => [
80 'bundle_selection_attributes' => $serializedBundleAttributes
82 $dataWithJsonEncodedBundleAttributes = [
83 'info_buyRequest' => [
87 'bundle_selection_attributes' => $jsonEncodedBundleAttributes
89 $this->serializeMock->expects($this->at(0))
90 ->method(
'unserialize')
91 ->with($serializedData)
93 $this->serializeMock->expects($this->at(1))
94 ->method(
'unserialize')
95 ->with($serializedBundleAttributes)
96 ->willReturn($bundleAttributes);
97 $this->jsonMock->expects($this->at(0))
99 ->with($bundleAttributes)
100 ->willReturn($jsonEncodedBundleAttributes);
101 $this->jsonMock->expects($this->at(1))
102 ->method(
'serialize')
103 ->with($dataWithJsonEncodedBundleAttributes)
104 ->willReturn($jsonEncodedData);
107 $this->serializedDataConverter->convert($serializedData)
113 $serializedData =
'serialized data';
114 $serializedOptionValue =
'serialized option value';
116 $jsonEncodedOptionValue =
'json encoded option value';
117 $jsonEncodedData =
'json encoded data';
119 'info_buyRequest' => [
125 'option_type' =>
'file',
126 'option_value' => $serializedOptionValue
129 'option_type' =>
'text',
130 'option_value' =>
'option 2' 134 $dataWithJsonEncodedOptionValue = [
135 'info_buyRequest' => [
141 'option_type' =>
'file',
142 'option_value' => $jsonEncodedOptionValue
145 'option_type' =>
'text',
146 'option_value' =>
'option 2' 150 $this->serializeMock->expects($this->at(0))
151 ->method(
'unserialize')
152 ->with($serializedData)
154 $this->serializeMock->expects($this->at(1))
155 ->method(
'unserialize')
156 ->with($serializedOptionValue)
158 $this->jsonMock->expects($this->at(0))
159 ->method(
'serialize')
161 ->willReturn($jsonEncodedOptionValue);
162 $this->jsonMock->expects($this->at(1))
163 ->method(
'serialize')
164 ->with($dataWithJsonEncodedOptionValue)
165 ->willReturn($jsonEncodedData);
168 $this->serializedDataConverter->convert($serializedData)
177 $this->serializeMock->expects($this->once())
178 ->method(
'unserialize')
179 ->willReturnCallback(
181 trigger_error(
'Can not unserialize string message', E_NOTICE);
184 $this->serializedDataConverter->convert(
'serialized data');
190 $this->serializeMock->expects($this->never())
191 ->method(
'unserialize');
192 $this->jsonMock->expects($this->never())
193 ->method(
'serialize');
194 $this->serializedDataConverter->convert($serialized);
testConvertBundleAttributes()
testConvertSkipConversion()
testConvertCustomOptionsTypeFile()
testConvertCorruptedData()