Skip to content
Snippets Groups Projects
Commit 7003dffd authored by Susan Wright's avatar Susan Wright Committed by GitHub
Browse files

Merge pull request #481 from...

Merge pull request #481 from magento-jackalopes/MAGETWO-58017-github-error-creating-configurable-products

Fixed issue:

- MAGETWO-58017 [GITHUB] Error creating configurable products in 2.1.1 #6424
parents 2d8fb52c 75e550e0
No related merge requests found
...@@ -11,6 +11,9 @@ ...@@ -11,6 +11,9 @@
<template> <template>
<minify_html>0</minify_html> <minify_html>0</minify_html>
</template> </template>
<static>
<sign>1</sign>
</static>
</dev> </dev>
<system> <system>
<media_storage_configuration> <media_storage_configuration>
......
...@@ -5,7 +5,8 @@ ...@@ -5,7 +5,8 @@
*/ */
namespace Magento\Framework\App\Test\Unit\View\Deployment; namespace Magento\Framework\App\Test\Unit\View\Deployment;
use \Magento\Framework\App\View\Deployment\Version; use Magento\Framework\App\View\Deployment\Version;
use Magento\Framework\Exception\FileSystemException;
/** /**
* Class VersionTest * Class VersionTest
...@@ -18,29 +19,39 @@ class VersionTest extends \PHPUnit_Framework_TestCase ...@@ -18,29 +19,39 @@ class VersionTest extends \PHPUnit_Framework_TestCase
private $object; private $object;
/** /**
* @var \PHPUnit_Framework_MockObject_MockObject * @var \Magento\Framework\App\State|\PHPUnit_Framework_MockObject_MockObject
*/ */
private $appState; private $appStateMock;
/** /**
* @var \PHPUnit_Framework_MockObject_MockObject * @var \Magento\Framework\App\View\Deployment\Version\StorageInterface|\PHPUnit_Framework_MockObject_MockObject
*/ */
private $versionStorage; private $versionStorageMock;
/**
* @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $loggerMock;
protected function setUp() protected function setUp()
{ {
$this->appState = $this->getMock(\Magento\Framework\App\State::class, [], [], '', false); $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->versionStorage = $this->getMock(\Magento\Framework\App\View\Deployment\Version\StorageInterface::class); $this->appStateMock = $this->getMock(\Magento\Framework\App\State::class, [], [], '', false);
$this->object = new Version($this->appState, $this->versionStorage); $this->versionStorageMock = $this->getMock(
\Magento\Framework\App\View\Deployment\Version\StorageInterface::class
);
$this->loggerMock = $this->getMock(\Psr\Log\LoggerInterface::class);
$this->object = new Version($this->appStateMock, $this->versionStorageMock);
$objectManager->setBackwardCompatibleProperty($this->object, 'logger', $this->loggerMock);
} }
public function testGetValueDeveloperMode() public function testGetValueDeveloperMode()
{ {
$this->appState $this->appStateMock
->expects($this->once()) ->expects($this->once())
->method('getMode') ->method('getMode')
->will($this->returnValue(\Magento\Framework\App\State::MODE_DEVELOPER)); ->will($this->returnValue(\Magento\Framework\App\State::MODE_DEVELOPER));
$this->versionStorage->expects($this->never())->method($this->anything()); $this->versionStorageMock->expects($this->never())->method($this->anything());
$this->assertInternalType('integer', $this->object->getValue()); $this->assertInternalType('integer', $this->object->getValue());
$this->object->getValue(); // Ensure computation occurs only once and result is cached in memory $this->object->getValue(); // Ensure computation occurs only once and result is cached in memory
} }
...@@ -51,12 +62,12 @@ class VersionTest extends \PHPUnit_Framework_TestCase ...@@ -51,12 +62,12 @@ class VersionTest extends \PHPUnit_Framework_TestCase
*/ */
public function testGetValueFromStorage($appMode) public function testGetValueFromStorage($appMode)
{ {
$this->appState $this->appStateMock
->expects($this->once()) ->expects($this->once())
->method('getMode') ->method('getMode')
->will($this->returnValue($appMode)); ->will($this->returnValue($appMode));
$this->versionStorage->expects($this->once())->method('load')->will($this->returnValue('123')); $this->versionStorageMock->expects($this->once())->method('load')->will($this->returnValue('123'));
$this->versionStorage->expects($this->never())->method('save'); $this->versionStorageMock->expects($this->never())->method('save');
$this->assertEquals('123', $this->object->getValue()); $this->assertEquals('123', $this->object->getValue());
$this->object->getValue(); // Ensure caching in memory $this->object->getValue(); // Ensure caching in memory
} }
...@@ -70,20 +81,106 @@ class VersionTest extends \PHPUnit_Framework_TestCase ...@@ -70,20 +81,106 @@ class VersionTest extends \PHPUnit_Framework_TestCase
]; ];
} }
public function testGetValueDefaultModeSaving() /**
{ * $param bool $isUnexpectedValueExceptionThrown
* $param bool $isFileSystemExceptionThrown
* @dataProvider getValueDefaultModeDataProvider
*/
public function testGetValueDefaultMode(
$isUnexpectedValueExceptionThrown,
$isFileSystemExceptionThrown = null
) {
$versionType = 'integer'; $versionType = 'integer';
$this->appState $this->appStateMock
->expects($this->once()) ->expects($this->once())
->method('getMode') ->method('getMode')
->will($this->returnValue(\Magento\Framework\App\State::MODE_DEFAULT)); ->willReturn(\Magento\Framework\App\State::MODE_DEFAULT);
$storageException = new \UnexpectedValueException('Does not exist in the storage'); if ($isUnexpectedValueExceptionThrown) {
$this->versionStorage $storageException = new \UnexpectedValueException('Does not exist in the storage');
->expects($this->once()) $this->versionStorageMock
->method('load') ->expects($this->once())
->will($this->throwException($storageException)); ->method('load')
$this->versionStorage->expects($this->once())->method('save')->with($this->isType($versionType)); ->will($this->throwException($storageException));
$this->versionStorageMock->expects($this->once())
->method('save')
->with($this->isType($versionType));
if ($isFileSystemExceptionThrown) {
$fileSystemException = new FileSystemException(
new \Magento\Framework\Phrase('Can not load static content version')
);
$this->versionStorageMock
->expects($this->once())
->method('save')
->will($this->throwException($fileSystemException));
$this->loggerMock->expects($this->once())
->method('critical')
->with('Can not save static content version.');
} else {
$this->loggerMock->expects($this->never())
->method('critical');
}
} else {
$this->versionStorageMock
->expects($this->once())
->method('load')
->willReturn(1475779229);
$this->loggerMock->expects($this->never())
->method('critical');
}
$this->assertInternalType($versionType, $this->object->getValue()); $this->assertInternalType($versionType, $this->object->getValue());
$this->object->getValue(); // Ensure caching in memory $this->object->getValue();
}
/**
* @return array
*/
public function getValueDefaultModeDataProvider()
{
return [
[false],
[true, false],
[true, true]
];
}
/**
* @param bool $isUnexpectedValueExceptionThrown
* @dataProvider getValueProductionModeDataProvider
*/
public function testGetValueProductionMode(
$isUnexpectedValueExceptionThrown
) {
$this->appStateMock
->expects($this->once())
->method('getMode')
->willReturn(\Magento\Framework\App\State::MODE_PRODUCTION);
if ($isUnexpectedValueExceptionThrown) {
$storageException = new \UnexpectedValueException('Does not exist in the storage');
$this->versionStorageMock
->expects($this->once())
->method('load')
->will($this->throwException($storageException));
$this->loggerMock->expects($this->once())
->method('critical')
->with('Can not load static content version.');
} else {
$this->versionStorageMock
->expects($this->once())
->method('load')
->willReturn(1475779229);
}
$this->assertInternalType('integer', $this->object->getValue());
$this->object->getValue();
}
/**
* @return array
*/
public function getValueProductionModeDataProvider()
{
return [
[false],
[true],
];
} }
} }
...@@ -6,6 +6,9 @@ ...@@ -6,6 +6,9 @@
namespace Magento\Framework\App\View\Deployment; namespace Magento\Framework\App\View\Deployment;
use Psr\Log\LoggerInterface;
use Magento\Framework\Exception\FileSystemException;
/** /**
* Deployment version of static files * Deployment version of static files
*/ */
...@@ -26,6 +29,11 @@ class Version ...@@ -26,6 +29,11 @@ class Version
*/ */
private $cachedValue; private $cachedValue;
/**
* @var LoggerInterface
*/
private $logger;
/** /**
* @param \Magento\Framework\App\State $appState * @param \Magento\Framework\App\State $appState
* @param Version\StorageInterface $versionStorage * @param Version\StorageInterface $versionStorage
...@@ -59,23 +67,49 @@ class Version ...@@ -59,23 +67,49 @@ class Version
*/ */
protected function readValue($appMode) protected function readValue($appMode)
{ {
switch ($appMode) { if ($appMode == \Magento\Framework\App\State::MODE_DEVELOPER) {
case \Magento\Framework\App\State::MODE_DEFAULT: $result = $this->generateVersion();
try { } else {
$result = $this->versionStorage->load(); try {
} catch (\UnexpectedValueException $e) { $result = $this->versionStorage->load();
$result = (new \DateTime())->getTimestamp(); } catch (\UnexpectedValueException $e) {
$this->versionStorage->save($result); $result = $this->generateVersion();
if ($appMode == \Magento\Framework\App\State::MODE_DEFAULT) {
try {
$this->versionStorage->save($result);
} catch (FileSystemException $e) {
$this->getLogger()->critical('Can not save static content version.');
}
} else {
$this->getLogger()->critical('Can not load static content version.');
} }
break; }
}
return $result;
}
case \Magento\Framework\App\State::MODE_DEVELOPER: /**
$result = (new \DateTime())->getTimestamp(); * Generate version of static content
break; *
* @return int
*/
private function generateVersion()
{
return time();
}
default: /**
$result = $this->versionStorage->load(); * Get logger
*
* @return LoggerInterface
* @deprecated
*/
private function getLogger()
{
if ($this->logger == null) {
$this->logger = \Magento\Framework\App\ObjectManager::getInstance()
->get(LoggerInterface::class);
} }
return $result; return $this->logger;
} }
} }
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment