diff --git a/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php b/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php index ac55963655b8700cd5322abfc4f95fea38de79a6..d1dc30ee7c9efc14554338eea9b6b00745e2e048 100644 --- a/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php +++ b/lib/internal/Magento/Framework/App/ObjectManager/ConfigLoader/Compiled.php @@ -11,8 +11,6 @@ use Magento\Framework\ObjectManager\ConfigLoaderInterface; class Compiled implements ConfigLoaderInterface { - const FILE_EXTENSION = '.json'; - /** * Global config * @@ -46,7 +44,7 @@ class Compiled implements ConfigLoaderInterface public static function getFilePath($area) { $diPath = DirectoryList::getDefaultConfig()[DirectoryList::DI][DirectoryList::PATH]; - return BP . $diPath . '/' . $area . self::FILE_EXTENSION; + return BP . $diPath . '/' . $area . '.json'; } /** diff --git a/lib/internal/Magento/Framework/App/ObjectManagerFactory.php b/lib/internal/Magento/Framework/App/ObjectManagerFactory.php index f91c389b493fb7421a9af7cad7ef9d4c450f2d90..bfe94a9dccc643aa99f005e2b52f445383755eca 100644 --- a/lib/internal/Magento/Framework/App/ObjectManagerFactory.php +++ b/lib/internal/Magento/Framework/App/ObjectManagerFactory.php @@ -10,7 +10,6 @@ namespace Magento\Framework\App; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Filesystem\DriverPool; use Magento\Framework\Interception\ObjectManager\ConfigInterface; -use Magento\Framework\ObjectManager\Definition\Compiled\Json; use Magento\Framework\App\ObjectManager\Environment; use Magento\Framework\Config\File\ConfigFilePool; use Magento\Framework\Code\GeneratedFiles; @@ -23,6 +22,7 @@ class ObjectManagerFactory { /** * Path to definitions format in deployment configuration + * @deprecated */ const CONFIG_PATH_DEFINITION_FORMAT = 'definition/format'; @@ -118,8 +118,7 @@ class ObjectManagerFactory $definitionFactory = new \Magento\Framework\ObjectManager\DefinitionFactory( $this->driverPool->getDriver(DriverPool::FILE), $this->directoryList->getPath(DirectoryList::DI), - $this->directoryList->getPath(DirectoryList::GENERATION), - $deploymentConfig->get(self::CONFIG_PATH_DEFINITION_FORMAT, Json::MODE_NAME) + $this->directoryList->getPath(DirectoryList::GENERATION) ); $definitions = $definitionFactory->createClassDefinition($deploymentConfig->get('definitions')); diff --git a/lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/ConfigCacheTest.php b/lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/ConfigCacheTest.php index 315bfeeb51f79583f211114684e4cd1c94aa3cf4..21dce94bb6c73a6962b30636e14b3cf97a2f2319 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/ConfigCacheTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/ConfigCacheTest.php @@ -63,9 +63,8 @@ class ConfigCacheTest extends \PHPUnit_Framework_TestCase ); $this->serializerMock->expects($this->once()) ->method('unserialize') - ->willReturnCallback(function ($string) { - return json_decode($string, true); - }); + ->with($loadData) + ->willReturn($expectedResult); $this->assertEquals($expectedResult, $this->configCache->get($key)); } @@ -73,7 +72,7 @@ class ConfigCacheTest extends \PHPUnit_Framework_TestCase { return [ [false, false], - [json_encode(['some data']), ['some data']], + ['["some data"]', ['some data']], ]; } @@ -83,10 +82,8 @@ class ConfigCacheTest extends \PHPUnit_Framework_TestCase $config = ['config']; $this->serializerMock->expects($this->once()) ->method('serialize') - ->willReturnCallback(function ($data) { - return json_encode($data); - }); - $this->cacheFrontendMock->expects($this->once())->method('save')->with(json_encode($config), 'diConfig' . $key); + ->willReturn('["config"]'); + $this->cacheFrontendMock->expects($this->once())->method('save')->with('["config"]', 'diConfig' . $key); $this->configCache->save($config, $key); } } diff --git a/lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/ConfigLoaderTest.php b/lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/ConfigLoaderTest.php index b5e7c46913949dd54dd4e017cd7fb4f579471057..bb048218a768ae40d93375a0a260188d6613f020 100644 --- a/lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/ConfigLoaderTest.php +++ b/lib/internal/Magento/Framework/App/Test/Unit/ObjectManager/ConfigLoaderTest.php @@ -88,6 +88,7 @@ class ConfigLoaderTest extends \PHPUnit_Framework_TestCase public function testLoadNotCached($area) { $configData = ['some' => 'config', 'data' => 'value']; + $serializedConfigData = '{"some":"config","data":"value"}'; $this->cacheMock->expects($this->once()) ->method('load') @@ -96,14 +97,13 @@ class ConfigLoaderTest extends \PHPUnit_Framework_TestCase $this->cacheMock->expects($this->once()) ->method('save') - ->with(json_encode($configData)); + ->with($serializedConfigData); $this->readerMock->expects($this->once())->method('read')->with($area)->will($this->returnValue($configData)); $this->serializerMock->expects($this->once()) ->method('serialize') - ->willReturnCallback(function ($string) { - return json_encode($string); - }); + ->willReturn($serializedConfigData); + $this->serializerMock->expects($this->never())->method('unserialize'); $this->assertEquals($configData, $this->object->load($area)); @@ -126,18 +126,18 @@ class ConfigLoaderTest extends \PHPUnit_Framework_TestCase public function testLoadCached() { $configData = ['some' => 'config', 'data' => 'value']; + $serializedConfigData = '{"some":"config","data":"value"}'; $this->cacheMock->expects($this->once()) ->method('load') - ->willReturn(json_encode($configData)); + ->willReturn($serializedConfigData); $this->cacheMock->expects($this->never()) ->method('save'); $this->readerMock->expects($this->never())->method('read'); $this->serializerMock->expects($this->once()) ->method('unserialize') - ->willReturnCallback(function ($string) { - return json_decode($string, true); - }); + ->with($serializedConfigData) + ->willReturn($configData); $this->serializerMock->expects($this->never())->method('serialize'); $this->assertEquals($configData, $this->object->load('testArea')); } diff --git a/lib/internal/Magento/Framework/Config/ConfigOptionsListConstants.php b/lib/internal/Magento/Framework/Config/ConfigOptionsListConstants.php index b6363520dc085c75ec44a1700094e328af1fb973..304174ac52d3792054221c27d53624f34ed2ca7e 100644 --- a/lib/internal/Magento/Framework/Config/ConfigOptionsListConstants.php +++ b/lib/internal/Magento/Framework/Config/ConfigOptionsListConstants.php @@ -37,7 +37,6 @@ class ConfigOptionsListConstants */ const INPUT_KEY_ENCRYPTION_KEY = 'key'; const INPUT_KEY_SESSION_SAVE = 'session-save'; - const INPUT_KEY_DEFINITION_FORMAT = 'definition-format'; const INPUT_KEY_DB_HOST = 'db-host'; const INPUT_KEY_DB_NAME = 'db-name'; const INPUT_KEY_DB_USER = 'db-user'; @@ -51,6 +50,9 @@ class ConfigOptionsListConstants const INPUT_KEY_CACHE_HOSTS = 'http-cache-hosts'; /**#@-*/ + /** @deprecated */ + const INPUT_KEY_DEFINITION_FORMAT = 'definition-format'; + /**#@+ * Values for session-save */ diff --git a/lib/internal/Magento/Framework/Interception/Definition/Compiled.php b/lib/internal/Magento/Framework/Interception/Definition/Compiled.php index 959d1da1026ee884724c24fc5b45ae4085a4ffc0..6fbe9c99dce8637e8c31b9ce493b5b79c45e62c0 100644 --- a/lib/internal/Magento/Framework/Interception/Definition/Compiled.php +++ b/lib/internal/Magento/Framework/Interception/Definition/Compiled.php @@ -11,8 +11,6 @@ use Magento\Framework\Interception\DefinitionInterface; class Compiled implements DefinitionInterface { - const FILE_NAME = 'plugins.json'; - /** * List of plugin definitions * diff --git a/lib/internal/Magento/Framework/Interception/Test/Unit/Config/ConfigTest.php b/lib/internal/Magento/Framework/Interception/Test/Unit/Config/ConfigTest.php index d51db8bc36469c3dd8842f1af14e4ff74c87ab61..db0218d00afc15674aeeaa89fa7415b1b6576bea 100644 --- a/lib/internal/Magento/Framework/Interception/Test/Unit/Config/ConfigTest.php +++ b/lib/internal/Magento/Framework/Interception/Test/Unit/Config/ConfigTest.php @@ -148,10 +148,8 @@ class ConfigTest extends \PHPUnit_Framework_TestCase $this->relationsMock->expects($this->any())->method('getParents')->will($this->returnValue($entityParents)); $this->serializerMock->expects($this->once()) - ->method('serialize') - ->willReturnCallback(function ($data) { - return json_encode($data); - }); + ->method('serialize'); + $this->serializerMock->expects($this->never())->method('unserialize'); $model = $this->objectManagerHelper->getObject( @@ -188,17 +186,23 @@ class ConfigTest extends \PHPUnit_Framework_TestCase ]; $this->readerMock->expects($this->never())->method('read'); $this->cacheMock->expects($this->never())->method('save'); + $serializedValue = '{"Magento\\Framework\\Interception\\Test\\Unit\\Custom\\Module\\Model\\ItemContainer":true,' + . '"Magento\\Framework\\Interception\\Test\\Unit\\Custom\\Module\\Model\\Item":true,' + . '"Magento\\Framework\\Interception\\Test\\Unit\\Custom\\Module\\Model\\Item\\Enhanced":true,' + . '"Magento\\Framework\\Interception\\Test\\Unit\\Custom\\Module\\Model\\ItemContainer\\Enhanced":true,' + . '"Magento\\Framework\\Interception\\Test\\Unit\\Custom\\Module\\Model\\ItemContainer\\Proxy":true,' + . '"Magento\\Framework\\Interception\\Test\\Unit\\Custom\\Module\\Model\\ItemProxy":false,' + . '"virtual_custom_item":true}'; $this->cacheMock->expects($this->any()) ->method('load') ->with($cacheId) - ->will($this->returnValue(json_encode($interceptionData))); + ->will($this->returnValue($serializedValue)); $this->serializerMock->expects($this->never())->method('serialize'); $this->serializerMock->expects($this->once()) ->method('unserialize') - ->willReturnCallback(function ($string) { - return json_decode($string, true); - }); + ->with($serializedValue) + ->willReturn($interceptionData); $model = $this->objectManagerHelper->getObject( \Magento\Framework\Interception\Config\Config::class, 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 e162cd37c789b9c77d77cc3cc30b92391688af67..dd0d2f68ac6ade78df90ca67931b491c9697b852 100644 --- a/lib/internal/Magento/Framework/Interception/Test/Unit/PluginList/PluginListTest.php +++ b/lib/internal/Magento/Framework/Interception/Test/Unit/PluginList/PluginListTest.php @@ -238,12 +238,7 @@ class PluginListTest extends \PHPUnit_Framework_TestCase ->method('getCurrentScope') ->will($this->returnValue('scope')); $this->serializerMock->expects($this->once()) - ->method('serialize') - ->willReturnCallback( - function ($data) { - return json_encode($data); - } - ); + ->method('serialize'); $this->serializerMock->expects($this->never()) ->method('unserialize'); $this->cacheMock->expects($this->once()) @@ -279,18 +274,17 @@ class PluginListTest extends \PHPUnit_Framework_TestCase ->will($this->returnValue('scope')); $data = [['key'], ['key'], ['key']]; + $serializedData = '[["key"],["key"],["key"]]'; $this->serializerMock->expects($this->never()) ->method('serialize'); $this->serializerMock->expects($this->once()) ->method('unserialize') - ->willReturnCallback(function ($string) { - return json_decode($string, true); - }); + ->willReturn($data); $this->cacheMock->expects($this->once()) ->method('load') ->with('global|scope|interception') - ->will($this->returnValue(json_encode($data))); + ->willReturn($serializedData); $this->assertEquals(null, $this->object->getNext('Type', 'method')); } diff --git a/lib/internal/Magento/Framework/ObjectManager/Definition/Compiled.php b/lib/internal/Magento/Framework/ObjectManager/Definition/Compiled.php index 2cb3b21211f23af76ab75ad6875b4cc6396f4a50..db91618dccd23e59d570ca967c54c61ace95bca1 100644 --- a/lib/internal/Magento/Framework/ObjectManager/Definition/Compiled.php +++ b/lib/internal/Magento/Framework/ObjectManager/Definition/Compiled.php @@ -5,10 +5,12 @@ */ namespace Magento\Framework\ObjectManager\Definition; +use Magento\Framework\Serialize\SerializerInterface; + /** * Compiled class definitions. Should be used for maximum performance in production. */ -abstract class Compiled implements \Magento\Framework\ObjectManager\DefinitionInterface +class Compiled implements \Magento\Framework\ObjectManager\DefinitionInterface { /** * Class definitions @@ -22,6 +24,16 @@ abstract class Compiled implements \Magento\Framework\ObjectManager\DefinitionIn */ protected $reader ; + /** + * @var SerializerInterface + */ + private $serializer; + + /** + * @var array + */ + private $_signatures; + /** * @param array $definitions * @param \Magento\Framework\Code\Reader\ClassReaderInterface $reader @@ -38,7 +50,10 @@ abstract class Compiled implements \Magento\Framework\ObjectManager\DefinitionIn * @param string $signature * @return mixed */ - abstract protected function _unpack($signature); + protected function _unpack($signature) + { + return $this->getSerializer()->unserialize($signature); + } /** * Get list of method parameters @@ -82,4 +97,19 @@ abstract class Compiled implements \Magento\Framework\ObjectManager\DefinitionIn { return array_keys($this->_definitions); } + + /** + * Get serializer + * + * @return SerializerInterface + * @deprecated + */ + private function getSerializer() + { + if ($this->serializer === null) { + $this->serializer = \Magento\Framework\App\ObjectManager::getInstance() + ->get(SerializerInterface::class); + } + return $this->serializer; + } } diff --git a/lib/internal/Magento/Framework/ObjectManager/Definition/Compiled/Json.php b/lib/internal/Magento/Framework/ObjectManager/Definition/Compiled/Json.php deleted file mode 100644 index f68e5203a23fe0d27c29aa6f4cf0a468e6932d4e..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/ObjectManager/Definition/Compiled/Json.php +++ /dev/null @@ -1,47 +0,0 @@ -<?php -/** - * Copyright © 2016 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework\ObjectManager\Definition\Compiled; - -use Magento\Framework\Serialize\SerializerInterface; - -class Json extends \Magento\Framework\ObjectManager\Definition\Compiled -{ - /** - * Mode name - */ - const MODE_NAME = 'json'; - - /** - * @var SerializerInterface - */ - private $serializer; - - /** - * Unpack signature - * - * @param string $signature - * @return mixed - */ - protected function _unpack($signature) - { - return $this->getSerializer()->unserialize($signature); - } - - /** - * Get serializer - * - * @return SerializerInterface - * @deprecated - */ - private function getSerializer() - { - if ($this->serializer === null) { - $this->serializer = \Magento\Framework\App\ObjectManager::getInstance() - ->get(SerializerInterface::class); - } - return $this->serializer; - } -} diff --git a/lib/internal/Magento/Framework/ObjectManager/DefinitionFactory.php b/lib/internal/Magento/Framework/ObjectManager/DefinitionFactory.php index ef906cb945a42ca6ddc12170ecf46b98f22ef249..4e9026eb7b20d239647c89c0ae77c473d092d6b4 100644 --- a/lib/internal/Magento/Framework/ObjectManager/DefinitionFactory.php +++ b/lib/internal/Magento/Framework/ObjectManager/DefinitionFactory.php @@ -13,7 +13,6 @@ namespace Magento\Framework\ObjectManager; use Magento\Framework\Filesystem\DriverInterface; use Magento\Framework\Interception\Code\Generator as InterceptionGenerator; -use Magento\Framework\ObjectManager\Definition\Compiled\Json; use Magento\Framework\ObjectManager\Definition\Runtime; use Magento\Framework\ObjectManager\Profiler\Code\Generator as ProfilerGenerator; @@ -40,6 +39,7 @@ class DefinitionFactory * Format of definitions * * @var string + * @deprecated */ protected $_definitionFormat; @@ -55,9 +55,7 @@ class DefinitionFactory * * @var array */ - protected static $definitionClasses = [ - Json::MODE_NAME => \Magento\Framework\ObjectManager\Definition\Compiled\Json::class, - ]; + protected static $definitionClasses = \Magento\Framework\ObjectManager\Definition\Compiled::class; /** * @var \Magento\Framework\Code\Generator @@ -70,8 +68,12 @@ class DefinitionFactory * @param string $generationDir * @param string $definitionFormat */ - public function __construct(DriverInterface $filesystemDriver, $definitionDir, $generationDir, $definitionFormat) - { + public function __construct( + DriverInterface $filesystemDriver, + $definitionDir, + $generationDir, + $definitionFormat = null + ) { $this->_filesystemDriver = $filesystemDriver; $this->_definitionDir = $definitionDir; $this->_generationDir = $generationDir; @@ -90,7 +92,7 @@ class DefinitionFactory if (is_string($definitions)) { $definitions = $this->_unpack($definitions); } - $definitionModel = self::$definitionClasses[$this->_definitionFormat]; + $definitionModel = self::$definitionClasses; $result = new $definitionModel($definitions); } else { $autoloader = new \Magento\Framework\Code\Generator\Autoloader($this->getCodeGenerator()); @@ -108,7 +110,7 @@ class DefinitionFactory */ public function createPluginDefinition() { - $path = $this->_definitionDir . '/' . \Magento\Framework\Interception\Definition\Compiled::FILE_NAME; + $path = $this->_definitionDir . '/plugins.json'; if ($this->_filesystemDriver->isReadable($path)) { return new \Magento\Framework\Interception\Definition\Compiled( $this->_unpack($this->_filesystemDriver->fileGetContents($path)) @@ -125,7 +127,7 @@ class DefinitionFactory */ public function createRelations() { - $path = $this->_definitionDir . '/' . \Magento\Framework\ObjectManager\Relations\Compiled::FILE_NAME; + $path = $this->_definitionDir . '/relations.json'; if ($this->_filesystemDriver->isReadable($path)) { return new \Magento\Framework\ObjectManager\Relations\Compiled( $this->_unpack($this->_filesystemDriver->fileGetContents($path)) @@ -139,10 +141,11 @@ class DefinitionFactory * Gets supported definition formats * * @return array + * @deprecated */ public static function getSupportedFormats() { - return array_keys(self::$definitionClasses); + return []; } /** diff --git a/lib/internal/Magento/Framework/ObjectManager/Relations/Compiled.php b/lib/internal/Magento/Framework/ObjectManager/Relations/Compiled.php index 56163410f351d5164187c97b5b537f31cadf71d3..71455dbf9acd49e7e7c6d93699934a89ede5827a 100644 --- a/lib/internal/Magento/Framework/ObjectManager/Relations/Compiled.php +++ b/lib/internal/Magento/Framework/ObjectManager/Relations/Compiled.php @@ -9,8 +9,6 @@ namespace Magento\Framework\ObjectManager\Relations; class Compiled implements \Magento\Framework\ObjectManager\RelationsInterface { - const FILE_NAME = 'relations.json'; - /** * List of class relations * diff --git a/lib/internal/Magento/Framework/ObjectManager/Test/Unit/Definition/Compiled/JsonTest.php b/lib/internal/Magento/Framework/ObjectManager/Test/Unit/Definition/Compiled/JsonTest.php deleted file mode 100644 index 4910eb0d2774aefdf2313ffc92c3e8906a261530..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/ObjectManager/Test/Unit/Definition/Compiled/JsonTest.php +++ /dev/null @@ -1,68 +0,0 @@ -<?php -/** - * Copyright © 2016 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework\ObjectManager\Test\Unit\Definition\Compiled; - -use Magento\Framework\Serialize\SerializerInterface; - -class JsonTest extends \PHPUnit_Framework_TestCase -{ - /** @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager */ - private $objectManagerHelper; - - protected function setUp() - { - $this->objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - } - - /** - * @param array $signatures - * @param array $definitions - * @param mixed $expected - * @dataProvider getParametersDataProvider - */ - public function testGetParametersWithoutDefinition($signatures, $definitions, $expected) - { - $model = new \Magento\Framework\ObjectManager\Definition\Compiled\Json([$signatures, $definitions]); - $this->assertEquals($expected, $model->getParameters('wonderful')); - } - - public function getParametersDataProvider() - { - $wonderfulSignature = new \stdClass(); - return [ - [ - [], - ['wonderful' => null], - null, - ], - [ - ['wonderfulClass' => $wonderfulSignature], - ['wonderful' => 'wonderfulClass'], - $wonderfulSignature, - ] - ]; - } - - public function testGetParametersWithUnpacking() - { - $checkString = 'code to pack'; - $signatures = ['wonderfulClass' => json_encode($checkString)]; - $definitions = ['wonderful' => 'wonderfulClass']; - $object = new \Magento\Framework\ObjectManager\Definition\Compiled\Json([$signatures, $definitions]); - $serializerMock = $this->getMock(SerializerInterface::class); - $serializerMock->expects($this->once()) - ->method('unserialize') - ->willReturnCallback(function ($data) { - return json_decode($data, true); - }); - $this->objectManagerHelper->setBackwardCompatibleProperty( - $object, - 'serializer', - $serializerMock - ); - $this->assertEquals($checkString, $object->getParameters('wonderful')); - } -} diff --git a/lib/internal/Magento/Framework/ObjectManager/Test/Unit/Definition/CompiledStub.php b/lib/internal/Magento/Framework/ObjectManager/Test/Unit/Definition/CompiledStub.php deleted file mode 100644 index bb5826a7b17ec9c115b2ce1d01bc43502e530c44..0000000000000000000000000000000000000000 --- a/lib/internal/Magento/Framework/ObjectManager/Test/Unit/Definition/CompiledStub.php +++ /dev/null @@ -1,25 +0,0 @@ -<?php -/** - * Copyright © 2016 Magento. All rights reserved. - * See COPYING.txt for license details. - */ -namespace Magento\Framework\ObjectManager\Test\Unit\Definition; - -use \Magento\Framework\ObjectManager\Definition\Compiled; - -/** - * Stub class for abstract Magento\Framework\ObjectManager\DefinitionInterface - */ -class CompiledStub extends Compiled -{ - /** - * Unpack signature - * - * @param string $signature - * @return mixed - */ - protected function _unpack($signature) - { - return json_decode($signature); - } -} diff --git a/lib/internal/Magento/Framework/ObjectManager/Test/Unit/Definition/CompiledTest.php b/lib/internal/Magento/Framework/ObjectManager/Test/Unit/Definition/CompiledTest.php index 0e7c79e8571d2686f561df97ed6832d93768d2fa..49616e6765874e603baf5d55eea7a641aa6a79b2 100644 --- a/lib/internal/Magento/Framework/ObjectManager/Test/Unit/Definition/CompiledTest.php +++ b/lib/internal/Magento/Framework/ObjectManager/Test/Unit/Definition/CompiledTest.php @@ -5,33 +5,64 @@ */ namespace Magento\Framework\ObjectManager\Test\Unit\Definition; -use \Magento\Framework\ObjectManager\Definition\Compiled; +use Magento\Framework\Serialize\SerializerInterface; class CompiledTest extends \PHPUnit_Framework_TestCase { - public function testGetParametersWithUndefinedDefinition() + /** @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager */ + private $objectManagerHelper; + + protected function setUp() { - $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); - $undefinedDefinitionSignature = new \stdClass(); - $className = 'undefinedDefinition'; - $readerMock = $this->getMock( - \Magento\Framework\Code\Reader\ClassReader::class, - ['getConstructor'], - [], - '', - false - ); - $readerMock->expects($this->once()) - ->method('getConstructor') - ->with($className) - ->willReturn($undefinedDefinitionSignature); - $model = $objectManager->getObject( - \Magento\Framework\ObjectManager\Test\Unit\Definition\CompiledStub::class, + $this->objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + } + + /** + * @param array $signatures + * @param array $definitions + * @param mixed $expected + * @dataProvider getParametersDataProvider + */ + public function testGetParametersWithoutDefinition($signatures, $definitions, $expected) + { + $model = new \Magento\Framework\ObjectManager\Definition\Compiled([$signatures, $definitions]); + $this->assertEquals($expected, $model->getParameters('wonderful')); + } + + public function getParametersDataProvider() + { + $wonderfulSignature = new \stdClass(); + return [ + [ + [], + ['wonderful' => null], + null, + ], [ - 'definitions' => [[], []], - 'reader' => $readerMock + ['wonderfulClass' => $wonderfulSignature], + ['wonderful' => 'wonderfulClass'], + $wonderfulSignature, ] + ]; + } + + public function testGetParametersWithUnpacking() + { + $checkString = 'code to pack'; + $signatures = ['wonderfulClass' => json_encode($checkString)]; + $definitions = ['wonderful' => 'wonderfulClass']; + $object = new \Magento\Framework\ObjectManager\Definition\Compiled([$signatures, $definitions]); + $serializerMock = $this->getMock(SerializerInterface::class); + $serializerMock->expects($this->once()) + ->method('unserialize') + ->willReturnCallback(function ($data) { + return json_decode($data, true); + }); + $this->objectManagerHelper->setBackwardCompatibleProperty( + $object, + 'serializer', + $serializerMock ); - $this->assertEquals($undefinedDefinitionSignature, $model->getParameters($className)); + $this->assertEquals($checkString, $object->getParameters('wonderful')); } } diff --git a/lib/internal/Magento/Framework/ObjectManager/Test/Unit/DefinitionFactoryTest.php b/lib/internal/Magento/Framework/ObjectManager/Test/Unit/DefinitionFactoryTest.php index 3051a671a4e7740114fa3c19c90459cb2b669e84..3861d274b5243e68efadb785635e1221ffef1208 100644 --- a/lib/internal/Magento/Framework/ObjectManager/Test/Unit/DefinitionFactoryTest.php +++ b/lib/internal/Magento/Framework/ObjectManager/Test/Unit/DefinitionFactoryTest.php @@ -6,7 +6,7 @@ namespace Magento\Framework\ObjectManager\Test\Unit; -use Magento\Framework\ObjectManager\Definition\Compiled\Json; +use Magento\Framework\ObjectManager\Definition\Compiled; class DefinitionFactoryTest extends \PHPUnit_Framework_TestCase { @@ -27,7 +27,7 @@ class DefinitionFactoryTest extends \PHPUnit_Framework_TestCase protected function setUp() { - $this->sampleContent = json_encode([1, 2, 3]); + $this->sampleContent = '[1,2,3]'; $this->filesystemDriverMock = $this->getMock( \Magento\Framework\Filesystem\Driver\File::class, [], @@ -38,15 +38,14 @@ class DefinitionFactoryTest extends \PHPUnit_Framework_TestCase $this->model = new \Magento\Framework\ObjectManager\DefinitionFactory( $this->filesystemDriverMock, 'DefinitionDir', - 'GenerationDir', - Json::MODE_NAME + 'GenerationDir' ); } public function testCreateClassDefinitionFromString() { $this->assertInstanceOf( - \Magento\Framework\ObjectManager\Definition\Compiled\Json::class, + \Magento\Framework\ObjectManager\Definition\Compiled::class, $this->model->createClassDefinition($this->sampleContent) ); } diff --git a/lib/internal/Magento/Framework/Reflection/Test/Unit/MethodsMapTest.php b/lib/internal/Magento/Framework/Reflection/Test/Unit/MethodsMapTest.php index 4fa07f938facf49ea40eb571c63fdc129ef2ea7c..35af774c7ba45fba1b49f52cb2779602f2deb8fd 100644 --- a/lib/internal/Magento/Framework/Reflection/Test/Unit/MethodsMapTest.php +++ b/lib/internal/Magento/Framework/Reflection/Test/Unit/MethodsMapTest.php @@ -87,10 +87,7 @@ class MethodsMapTest extends \PHPUnit_Framework_TestCase public function testGetMethodsMap() { $this->serializerMock->expects($this->once()) - ->method('serialize') - ->willReturnCallback(function ($data) { - return json_encode($data); - }); + ->method('serialize'); $methodsMap = $this->object->getMethodsMap(\Magento\Framework\Reflection\MethodsMap::class); $this->assertEquals( [ diff --git a/setup/src/Magento/Setup/Model/ConfigGenerator.php b/setup/src/Magento/Setup/Model/ConfigGenerator.php index 140f5a739889c829efe34689c044310a4d7d62a3..27b3999985743869cdf76fdb3c919d5c56bfecdd 100644 --- a/setup/src/Magento/Setup/Model/ConfigGenerator.php +++ b/setup/src/Magento/Setup/Model/ConfigGenerator.php @@ -116,19 +116,11 @@ class ConfigGenerator * * @param array $data * @return ConfigData + * @deprecated */ public function createDefinitionsConfig(array $data) { - $configData = new ConfigData(ConfigFilePool::APP_ENV); - - if (!empty($data[ConfigOptionsListConstants::INPUT_KEY_DEFINITION_FORMAT])) { - $configData->set( - ObjectManagerFactory::CONFIG_PATH_DEFINITION_FORMAT, - $data[ConfigOptionsListConstants::INPUT_KEY_DEFINITION_FORMAT] - ); - } - - return $configData; + return null; } /** diff --git a/setup/src/Magento/Setup/Model/ConfigOptionsList.php b/setup/src/Magento/Setup/Model/ConfigOptionsList.php index 4e8374aabb4e6b647aca8c34ca67041ca3532c54..0c1419a73cb8ebdb805dde29cc3412203dab7b07 100644 --- a/setup/src/Magento/Setup/Model/ConfigOptionsList.php +++ b/setup/src/Magento/Setup/Model/ConfigOptionsList.php @@ -72,13 +72,6 @@ class ConfigOptionsList implements ConfigOptionsListInterface 'Session save handler', ConfigOptionsListConstants::SESSION_SAVE_FILES ), - new SelectConfigOption( - ConfigOptionsListConstants::INPUT_KEY_DEFINITION_FORMAT, - SelectConfigOption::FRONTEND_WIZARD_SELECT, - DefinitionFactory::getSupportedFormats(), - ObjectManagerFactory::CONFIG_PATH_DEFINITION_FORMAT, - 'Type of definitions used by Object Manager' - ), new TextConfigOption( ConfigOptionsListConstants::INPUT_KEY_DB_HOST, TextConfigOption::FRONTEND_WIZARD_TEXT, diff --git a/setup/src/Magento/Setup/Module/Di/Compiler/Config/Writer/Filesystem.php b/setup/src/Magento/Setup/Module/Di/Compiler/Config/Writer/Filesystem.php index d384303d5e31a181e0b0c685c2bb6cec6a40f46b..add2b0adc8a111f6b3e9a0af2e21994cdb12233e 100644 --- a/setup/src/Magento/Setup/Module/Di/Compiler/Config/Writer/Filesystem.php +++ b/setup/src/Magento/Setup/Module/Di/Compiler/Config/Writer/Filesystem.php @@ -45,8 +45,7 @@ class Filesystem implements WriterInterface $this->initialize(); file_put_contents( - $this->directoryList->getPath(DirectoryList::DI) . '/' . $key - . \Magento\Framework\App\ObjectManager\ConfigLoader\Compiled::FILE_EXTENSION, + \Magento\Framework\App\ObjectManager\ConfigLoader\Compiled::getFilePath($key), $this->getSerializer()->serialize($config) ); } diff --git a/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsListTest.php b/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsListTest.php index 1e37d351d8f039014ae35a9fdfbe3aaa725375fe..eaab4d28d7620ebdc31c97b9a938afdb59957f55 100644 --- a/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsListTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Model/ConfigOptionsListTest.php @@ -48,32 +48,30 @@ class ConfigOptionsListTest extends \PHPUnit_Framework_TestCase $this->assertSame('Encryption key', $options[0]->getDescription()); $this->assertInstanceOf(\Magento\Framework\Setup\Option\SelectConfigOption::class, $options[1]); $this->assertSame('Session save handler', $options[1]->getDescription()); - $this->assertInstanceOf(\Magento\Framework\Setup\Option\SelectConfigOption::class, $options[2]); - $this->assertSame('Type of definitions used by Object Manager', $options[2]->getDescription()); + $this->assertInstanceOf(\Magento\Framework\Setup\Option\TextConfigOption::class, $options[2]); + $this->assertSame('Database server host', $options[2]->getDescription()); $this->assertInstanceOf(\Magento\Framework\Setup\Option\TextConfigOption::class, $options[3]); - $this->assertSame('Database server host', $options[3]->getDescription()); + $this->assertSame('Database name', $options[3]->getDescription()); $this->assertInstanceOf(\Magento\Framework\Setup\Option\TextConfigOption::class, $options[4]); - $this->assertSame('Database name', $options[4]->getDescription()); + $this->assertSame('Database server username', $options[4]->getDescription()); $this->assertInstanceOf(\Magento\Framework\Setup\Option\TextConfigOption::class, $options[5]); - $this->assertSame('Database server username', $options[5]->getDescription()); + $this->assertSame('Database server engine', $options[5]->getDescription()); $this->assertInstanceOf(\Magento\Framework\Setup\Option\TextConfigOption::class, $options[6]); - $this->assertSame('Database server engine', $options[6]->getDescription()); + $this->assertSame('Database server password', $options[6]->getDescription()); $this->assertInstanceOf(\Magento\Framework\Setup\Option\TextConfigOption::class, $options[7]); - $this->assertSame('Database server password', $options[7]->getDescription()); + $this->assertSame('Database table prefix', $options[7]->getDescription()); $this->assertInstanceOf(\Magento\Framework\Setup\Option\TextConfigOption::class, $options[8]); - $this->assertSame('Database table prefix', $options[8]->getDescription()); + $this->assertSame('Database type', $options[8]->getDescription()); $this->assertInstanceOf(\Magento\Framework\Setup\Option\TextConfigOption::class, $options[9]); - $this->assertSame('Database type', $options[9]->getDescription()); - $this->assertInstanceOf(\Magento\Framework\Setup\Option\TextConfigOption::class, $options[10]); - $this->assertSame('Database initial set of commands', $options[10]->getDescription()); - $this->assertInstanceOf(\Magento\Framework\Setup\Option\FlagConfigOption::class, $options[11]); + $this->assertSame('Database initial set of commands', $options[9]->getDescription()); + $this->assertInstanceOf(\Magento\Framework\Setup\Option\FlagConfigOption::class, $options[10]); $this->assertSame( 'If specified, then db connection validation will be skipped', - $options[11]->getDescription() + $options[10]->getDescription() ); - $this->assertInstanceOf(\Magento\Framework\Setup\Option\TextConfigOption::class, $options[12]); - $this->assertSame('http Cache hosts', $options[12]->getDescription()); - $this->assertEquals(13, count($options)); + $this->assertInstanceOf(\Magento\Framework\Setup\Option\TextConfigOption::class, $options[11]); + $this->assertSame('http Cache hosts', $options[11]->getDescription()); + $this->assertEquals(12, count($options)); } public function testCreateOptions() diff --git a/setup/src/Magento/Setup/Test/Unit/Module/ConfigGeneratorTest.php b/setup/src/Magento/Setup/Test/Unit/Module/ConfigGeneratorTest.php index caca5509d1e14ee4500803d05275d543692393f1..238bf7ea3db9f2f48be1414aaa2f7ad9783ce78c 100644 --- a/setup/src/Magento/Setup/Test/Unit/Module/ConfigGeneratorTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Module/ConfigGeneratorTest.php @@ -66,14 +66,6 @@ class ConfigGeneratorTest extends \PHPUnit_Framework_TestCase $this->assertEquals([], $returnValue->getData()); } - public function testCreateDefinitionsConfig() - { - $testData = [ConfigOptionsListConstants::INPUT_KEY_DEFINITION_FORMAT => 'test-format']; - $returnValue = $this->configGeneratorObject->createDefinitionsConfig($testData); - $this->assertEquals(ConfigFilePool::APP_ENV, $returnValue->getFileKey()); - $this->assertEquals(['definition' => ['format' => 'test-format']], $returnValue->getData()); - } - public function testCreateDbConfig() { $testData = [