From 2f3a64b411487af1ccaf59690227c30c483713ad Mon Sep 17 00:00:00 2001 From: Igor Melnikov <imelnikov@magento.com> Date: Thu, 3 Nov 2016 09:36:11 -0500 Subject: [PATCH] MAGETWO-60353: Replace json_decode in \Magento\Framework\ObjectManager\DefinitionFactory::_unpack with SerializerInterface Refactoring tests --- app/code/Magento/Cron/Model/Config/Data.php | 4 ---- .../Magento/Cron/Model/Groups/Config/Data.php | 3 --- .../Magento/Customer/Model/Address/Config.php | 6 +----- .../Model/Customer/NotificationStorageTest.php | 6 +++--- app/code/Magento/Sales/Model/Config/Data.php | 4 ---- .../Api/ExtensionAttribute/Config.php | 3 +++ .../Magento/Framework/Config/Data/Scoped.php | 2 -- .../Config/Test/Unit/Data/ScopedTest.php | 6 +----- .../Framework/Config/Test/Unit/DataTest.php | 12 ++++++------ .../Framework/DataObject/Copy/Config/Data.php | 2 -- .../Test/Unit/PluginList/PluginListTest.php | 18 +++++++++--------- 11 files changed, 23 insertions(+), 43 deletions(-) diff --git a/app/code/Magento/Cron/Model/Config/Data.php b/app/code/Magento/Cron/Model/Config/Data.php index 5b2f638609d..0e685aa9102 100644 --- a/app/code/Magento/Cron/Model/Config/Data.php +++ b/app/code/Magento/Cron/Model/Config/Data.php @@ -3,10 +3,6 @@ * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ - -/** - * Prepare cron jobs data - */ namespace Magento\Cron\Model\Config; use Magento\Framework\Serialize\SerializerInterface; diff --git a/app/code/Magento/Cron/Model/Groups/Config/Data.php b/app/code/Magento/Cron/Model/Groups/Config/Data.php index 2f400c642ed..5c69cf9667b 100644 --- a/app/code/Magento/Cron/Model/Groups/Config/Data.php +++ b/app/code/Magento/Cron/Model/Groups/Config/Data.php @@ -7,9 +7,6 @@ namespace Magento\Cron\Model\Groups\Config; use Magento\Framework\Serialize\SerializerInterface; -/** - * Prepare cron jobs data - */ class Data extends \Magento\Framework\Config\Data { /** diff --git a/app/code/Magento/Customer/Model/Address/Config.php b/app/code/Magento/Customer/Model/Address/Config.php index dc2ceede663..7170cf3d238 100644 --- a/app/code/Magento/Customer/Model/Address/Config.php +++ b/app/code/Magento/Customer/Model/Address/Config.php @@ -12,8 +12,6 @@ use Magento\Store\Model\ScopeInterface; /** * Customer address config - * - * @author Magento Core Team <core@magentocommerce.com> */ class Config extends ConfigData { @@ -24,7 +22,7 @@ class Config extends ConfigData const DEFAULT_ADDRESS_FORMAT = 'oneline'; /** - * Customer Address Templates per store + * Customer address templates per store * * @var array */ @@ -61,8 +59,6 @@ class Config extends ConfigData protected $_scopeConfig; /** - * Config constructor - * * @param Config\Reader $reader * @param \Magento\Framework\Config\CacheInterface $cache * @param \Magento\Store\Model\StoreManagerInterface $storeManager diff --git a/app/code/Magento/Customer/Test/Unit/Model/Customer/NotificationStorageTest.php b/app/code/Magento/Customer/Test/Unit/Model/Customer/NotificationStorageTest.php index e75cacc0781..644d0a2d701 100644 --- a/app/code/Magento/Customer/Test/Unit/Model/Customer/NotificationStorageTest.php +++ b/app/code/Magento/Customer/Test/Unit/Model/Customer/NotificationStorageTest.php @@ -45,15 +45,15 @@ class NotificationStorageTest extends \PHPUnit_Framework_TestCase 'customer_id' => $customerId, 'notification_type' => $notificationType ]; - $jsonString = json_encode($data); + $serializedData = 'serialized data'; $this->serializerMock->expects($this->once()) ->method('serialize') ->with($data) - ->willReturn($jsonString); + ->willReturn($serializedData); $this->cacheMock->expects($this->once()) ->method('save') ->with( - $jsonString, + $serializedData, $this->getCacheKey($notificationType, $customerId) ); $this->notificationStorage->add($notificationType, $customerId); diff --git a/app/code/Magento/Sales/Model/Config/Data.php b/app/code/Magento/Sales/Model/Config/Data.php index 0d44c627d55..bbd90a302f6 100644 --- a/app/code/Magento/Sales/Model/Config/Data.php +++ b/app/code/Magento/Sales/Model/Config/Data.php @@ -3,10 +3,6 @@ * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ - -/** - * Sales configuration data container - */ namespace Magento\Sales\Model\Config; use Magento\Framework\Serialize\SerializerInterface; diff --git a/lib/internal/Magento/Framework/Api/ExtensionAttribute/Config.php b/lib/internal/Magento/Framework/Api/ExtensionAttribute/Config.php index 3c5dd0bf415..32d2b75ed5e 100644 --- a/lib/internal/Magento/Framework/Api/ExtensionAttribute/Config.php +++ b/lib/internal/Magento/Framework/Api/ExtensionAttribute/Config.php @@ -14,6 +14,9 @@ use Magento\Framework\Serialize\SerializerInterface; */ class Config extends \Magento\Framework\Config\Data { + /** + * Cache identifier + */ const CACHE_ID = 'extension_attributes_config'; /** diff --git a/lib/internal/Magento/Framework/Config/Data/Scoped.php b/lib/internal/Magento/Framework/Config/Data/Scoped.php index 0171c97ff1e..55a354f0d2a 100644 --- a/lib/internal/Magento/Framework/Config/Data/Scoped.php +++ b/lib/internal/Magento/Framework/Config/Data/Scoped.php @@ -53,8 +53,6 @@ class Scoped extends \Magento\Framework\Config\Data protected $_loadedScopes = []; /** - * Constructor - * * @param \Magento\Framework\Config\ReaderInterface $reader * @param \Magento\Framework\Config\ScopeInterface $configScope * @param \Magento\Framework\Config\CacheInterface $cache diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/Data/ScopedTest.php b/lib/internal/Magento/Framework/Config/Test/Unit/Data/ScopedTest.php index 6e89bf9d50a..607977b99bb 100644 --- a/lib/internal/Magento/Framework/Config/Test/Unit/Data/ScopedTest.php +++ b/lib/internal/Magento/Framework/Config/Test/Unit/Data/ScopedTest.php @@ -52,13 +52,9 @@ class ScopedTest extends \PHPUnit_Framework_TestCase 'configScope' => $this->_configScopeMock, 'cache' => $this->_cacheMock, 'cacheId' => 'tag', + 'serializer' => $this->serializerMock ] ); - $this->objectManager->setBackwardCompatibleProperty( - $this->_model, - 'serializer', - $this->serializerMock - ); } /** diff --git a/lib/internal/Magento/Framework/Config/Test/Unit/DataTest.php b/lib/internal/Magento/Framework/Config/Test/Unit/DataTest.php index 5ad20aead09..c37d2108191 100644 --- a/lib/internal/Magento/Framework/Config/Test/Unit/DataTest.php +++ b/lib/internal/Magento/Framework/Config/Test/Unit/DataTest.php @@ -60,16 +60,16 @@ class DataTest extends \PHPUnit_Framework_TestCase public function testGetConfigCached() { $data = ['a' => 'b']; - $jsonString = '{"a":"b"}'; + $serializedData = '{"a":"b"}'; $cacheId = 'test'; $this->cacheMock->expects($this->once()) ->method('load') - ->willReturn($jsonString); + ->willReturn($serializedData); $this->readerMock->expects($this->never()) ->method('read'); $this->serializerMock->expects($this->once()) ->method('unserialize') - ->with($jsonString) + ->with($serializedData) ->willReturn($data); $config = new \Magento\Framework\Config\Data( $this->readerMock, @@ -83,14 +83,14 @@ class DataTest extends \PHPUnit_Framework_TestCase public function testReset() { - $jsonString = ''; + $serializedData = ''; $cacheId = 'test'; $this->cacheMock->expects($this->once()) ->method('load') - ->willReturn($jsonString); + ->willReturn($serializedData); $this->serializerMock->expects($this->once()) ->method('unserialize') - ->with($jsonString) + ->with($serializedData) ->willReturn([]); $this->cacheMock->expects($this->once()) ->method('remove') diff --git a/lib/internal/Magento/Framework/DataObject/Copy/Config/Data.php b/lib/internal/Magento/Framework/DataObject/Copy/Config/Data.php index 61802637750..731eb9d685d 100644 --- a/lib/internal/Magento/Framework/DataObject/Copy/Config/Data.php +++ b/lib/internal/Magento/Framework/DataObject/Copy/Config/Data.php @@ -1,7 +1,5 @@ <?php /** - * Fieldset configuration data container. Provides fieldset configuration data. - * * Copyright © 2016 Magento. All rights reserved. * See COPYING.txt for license details. */ diff --git a/lib/internal/Magento/Framework/Interception/Test/Unit/PluginList/PluginListTest.php b/lib/internal/Magento/Framework/Interception/Test/Unit/PluginList/PluginListTest.php index f70af781df6..282595e4a57 100644 --- a/lib/internal/Magento/Framework/Interception/Test/Unit/PluginList/PluginListTest.php +++ b/lib/internal/Magento/Framework/Interception/Test/Unit/PluginList/PluginListTest.php @@ -37,10 +37,14 @@ class PluginListTest extends \PHPUnit_Framework_TestCase */ private $cacheMock; - /** @var SerializerInterface|\PHPUnit_Framework_MockObject_MockObject */ + /** + * @var SerializerInterface|\PHPUnit_Framework_MockObject_MockObject + */ private $serializerMock; - /** @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject */ + /** + * @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject + */ private $loggerMock; protected function setUp() @@ -64,6 +68,7 @@ class PluginListTest extends \PHPUnit_Framework_TestCase $objectManagerMock = $this->getMock(\Magento\Framework\ObjectManagerInterface::class); $objectManagerMock->expects($this->any())->method('get')->will($this->returnArgument(0)); + $this->serializerMock = $this->getMock(SerializerInterface::class); $definitions = new \Magento\Framework\ObjectManager\Definition\Runtime(); @@ -80,15 +85,10 @@ class PluginListTest extends \PHPUnit_Framework_TestCase 'objectManager' => $objectManagerMock, 'classDefinitions' => $definitions, 'scopePriorityScheme' => ['global'], - 'cacheId' => 'interception' + 'cacheId' => 'interception', + 'serializer' => $this->serializerMock ] ); - $this->serializerMock = $this->getMock(SerializerInterface::class); - $objectManagerHelper->setBackwardCompatibleProperty( - $this->object, - 'serializer', - $this->serializerMock - ); $this->loggerMock = $this->getMock(\Psr\Log\LoggerInterface::class); $objectManagerHelper->setBackwardCompatibleProperty( -- GitLab