diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Product/Attribute/Source/CountryofmanufactureTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Product/Attribute/Source/CountryofmanufactureTest.php index 8c0e090bfe941c2525eabd2159ee27809137c151..9ae3f94924855cbda533691292af8d110e7e07da 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Product/Attribute/Source/CountryofmanufactureTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Product/Attribute/Source/CountryofmanufactureTest.php @@ -32,6 +32,11 @@ class CountryofmanufactureTest extends \PHPUnit_Framework_TestCase /** @var \Magento\Catalog\Model\Product\Attribute\Source\Countryofmanufacture */ private $countryOfManufacture; + /** + * @var \Magento\Framework\Serialize\SerializerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $serializerMock; + protected function setUp() { $this->storeManagerMock = $this->getMock(\Magento\Store\Model\StoreManagerInterface::class); @@ -46,19 +51,11 @@ class CountryofmanufactureTest extends \PHPUnit_Framework_TestCase ] ); - $serializerMock = $this->getMock(SerializerInterface::class, [], [], '', false); - $serializerMock->method('serialize') - ->willReturnCallback(function ($string) { - return json_encode($string); - }); - $serializerMock->method('unserialize') - ->willReturnCallback(function ($string) { - return json_decode($string, true); - }); + $this->serializerMock = $this->getMock(SerializerInterface::class, [], [], '', false); $this->objectManagerHelper->setBackwardCompatibleProperty( $this->countryOfManufacture, 'serializer', - $serializerMock + $this->serializerMock ); } @@ -78,7 +75,9 @@ class CountryofmanufactureTest extends \PHPUnit_Framework_TestCase ->method('load') ->with($this->equalTo('COUNTRYOFMANUFACTURE_SELECT_STORE_store_code')) ->will($this->returnValue($cachedDataSrl)); - + $this->serializerMock->expects($this->once()) + ->method('unserialize') + ->willReturn($cachedDataUnsrl); $this->assertEquals($cachedDataUnsrl, $this->countryOfManufacture->getAllOptions()); } diff --git a/app/code/Magento/Directory/Test/Unit/Block/DataTest.php b/app/code/Magento/Directory/Test/Unit/Block/DataTest.php index 6b41140240a30c2214ef6e1ce653dc7c559bfa51..5aabfe04708bf005735f5a4ce1e8da9a196204b1 100644 --- a/app/code/Magento/Directory/Test/Unit/Block/DataTest.php +++ b/app/code/Magento/Directory/Test/Unit/Block/DataTest.php @@ -80,13 +80,9 @@ class DataTest extends \PHPUnit_Framework_TestCase $serializerMock = $this->getMock(SerializerInterface::class, [], [], '', false); $serializerMock->method('serialize') - ->willReturnCallback(function ($string) { - return json_encode($string); - }); + ->willReturn('serializedData'); $serializerMock->method('unserialize') - ->willReturnCallback(function ($string) { - return json_decode($string, true); - }); + ->willReturn(['unserializedData']); $objectManagerHelper->setBackwardCompatibleProperty( $this->block, 'serializer', diff --git a/app/code/Magento/Webapi/Test/Unit/Model/DataObjectProcessorTest.php b/app/code/Magento/Webapi/Test/Unit/Model/DataObjectProcessorTest.php index 8c62cfcbc09d4c20f6b6972a5cc772499fee8015..0565832932a3fcd9bcfacf491759a27370bbc1dd 100644 --- a/app/code/Magento/Webapi/Test/Unit/Model/DataObjectProcessorTest.php +++ b/app/code/Magento/Webapi/Test/Unit/Model/DataObjectProcessorTest.php @@ -34,13 +34,10 @@ class DataObjectProcessorTest extends \PHPUnit_Framework_TestCase ); $serializerMock = $this->getMock(SerializerInterface::class); $serializerMock->method('serialize') - ->willReturnCallback(function ($data) { - return json_encode($data); - }); + ->willReturn('serializedData'); $serializerMock->method('unserialize') - ->willReturnCallback(function ($string) { - return json_decode($string, true); - }); + ->willReturn(['unserializedData']); + $objectManager->setBackwardCompatibleProperty( $methodsMapProcessor, 'serializer', diff --git a/lib/internal/Magento/Framework/App/Test/Unit/Route/ConfigTest.php b/lib/internal/Magento/Framework/App/Test/Unit/Route/ConfigTest.php index 2d30c9ae48893145282efa124a628c7799b783c2..05bbf68daf5af5eb5d335032fe158b9690ce462b 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/Route/ConfigTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/Route/ConfigTest.php @@ -32,6 +32,11 @@ class ConfigTest extends \PHPUnit_Framework_TestCase */ protected $_areaList; + /** + * @var \Magento\Framework\Serialize\SerializerInterface|\PHPUnit_Framework_MockObject_MockObject + */ + private $serializerMock; + protected function setUp() { $this->_readerMock = $this->getMock(\Magento\Framework\App\Route\Config\Reader::class, [], [], '', false); @@ -51,16 +56,8 @@ class ConfigTest extends \PHPUnit_Framework_TestCase 'areaList' => $this->_areaList ] ); - $serializerMock = $this->getMock(\Magento\Framework\Serialize\SerializerInterface::class); - $objectManager->setBackwardCompatibleProperty($this->_config, 'serializer', $serializerMock); - $serializerMock->method('serialize') - ->willReturnCallback(function ($string) { - return json_encode($string); - }); - $serializerMock->method('unserialize') - ->willReturnCallback(function ($string) { - return json_decode($string, true); - }); + $this->serializerMock = $this->getMock(\Magento\Framework\Serialize\SerializerInterface::class); + $objectManager->setBackwardCompatibleProperty($this->_config, 'serializer', $this->serializerMock); } public function testGetRouteFrontNameIfCacheIfRouterIdNotExist() @@ -74,14 +71,14 @@ class ConfigTest extends \PHPUnit_Framework_TestCase public function testGetRouteByFrontName() { + $data = ['routerCode' => ['frontName' => 'routerName']]; + $serializedData = json_encode($data); $this->_cacheMock->expects($this->once()) ->method('load') ->with('areaCode::RoutesConfig') - ->willReturn(json_encode(['routerCode' => ['frontName' => 'routerName']])); - - $this->assertEquals('routerCode', $this->_config->getRouteByFrontName('routerName')); - - // check internal caching in $this->_routes array + ->willReturn($serializedData); + $this->serializerMock->method('unserialize') + ->willReturn($data); $this->assertEquals('routerCode', $this->_config->getRouteByFrontName('routerName')); } @@ -90,11 +87,9 @@ class ConfigTest extends \PHPUnit_Framework_TestCase $this->_cacheMock->expects($this->once()) ->method('load') ->with('areaCode::RoutesConfig') - ->willReturn(json_encode([])); - - $this->assertFalse($this->_config->getRouteByFrontName('routerName')); - - // check caching in $this->_routes array + ->willReturn('[]'); + $this->serializerMock->method('unserialize') + ->willReturn([]); $this->assertFalse($this->_config->getRouteByFrontName('routerName')); } @@ -117,6 +112,8 @@ class ConfigTest extends \PHPUnit_Framework_TestCase ], ]; + $serializedData = json_encode($routes); + $this->_readerMock->expects( $this->once() )->method( @@ -137,24 +134,26 @@ class ConfigTest extends \PHPUnit_Framework_TestCase $this->returnValue('default_router') ); + $this->serializerMock->method('serialize') + ->willReturn($serializedData); + $this->_cacheMock->expects($this->once()) ->method('save') - ->with(json_encode($routes), 'scope::RoutesConfig'); - - $this->assertEquals('routerCode', $this->_config->getRouteByFrontName('routerName', 'scope')); + ->with($serializedData, 'scope::RoutesConfig'); - // check caching in $this->_routes array $this->assertEquals('routerCode', $this->_config->getRouteByFrontName('routerName', 'scope')); } public function testGetModulesByFrontName() { + $data = ['routerCode' => ['frontName' => 'routerName', 'modules' => ['Module1']]]; + $serializedData = json_encode($data); $this->_cacheMock->expects($this->once()) ->method('load') ->with('areaCode::RoutesConfig') - ->willReturn( - json_encode(['routerCode' => ['frontName' => 'routerName', 'modules' => ['Module1']]]) - ); + ->willReturn($serializedData); + $this->serializerMock->method('unserialize') + ->willReturn($data); $this->assertEquals(['Module1'], $this->_config->getModulesByFrontName('routerName')); } }