Skip to content

Commit

Permalink
Merge pull request #481 from magento-jackalopes/MAGETWO-58017-github-…
Browse files Browse the repository at this point in the history
…error-creating-configurable-products

Fixed issue:

- MAGETWO-58017 [GITHUB] Error creating configurable products in 2.1.1 #6424
  • Loading branch information
sdwright authored Oct 7, 2016
2 parents 2d8fb52 + 75e550e commit 7003dff
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 38 deletions.
3 changes: 3 additions & 0 deletions app/code/Magento/Backend/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<template>
<minify_html>0</minify_html>
</template>
<static>
<sign>1</sign>
</static>
</dev>
<system>
<media_storage_configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
*/
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
Expand All @@ -18,29 +19,39 @@ class VersionTest extends \PHPUnit_Framework_TestCase
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()
{
$this->appState = $this->getMock(\Magento\Framework\App\State::class, [], [], '', false);
$this->versionStorage = $this->getMock(\Magento\Framework\App\View\Deployment\Version\StorageInterface::class);
$this->object = new Version($this->appState, $this->versionStorage);
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$this->appStateMock = $this->getMock(\Magento\Framework\App\State::class, [], [], '', false);
$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()
{
$this->appState
$this->appStateMock
->expects($this->once())
->method('getMode')
->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->object->getValue(); // Ensure computation occurs only once and result is cached in memory
}
Expand All @@ -51,12 +62,12 @@ public function testGetValueDeveloperMode()
*/
public function testGetValueFromStorage($appMode)
{
$this->appState
$this->appStateMock
->expects($this->once())
->method('getMode')
->will($this->returnValue($appMode));
$this->versionStorage->expects($this->once())->method('load')->will($this->returnValue('123'));
$this->versionStorage->expects($this->never())->method('save');
$this->versionStorageMock->expects($this->once())->method('load')->will($this->returnValue('123'));
$this->versionStorageMock->expects($this->never())->method('save');
$this->assertEquals('123', $this->object->getValue());
$this->object->getValue(); // Ensure caching in memory
}
Expand All @@ -70,20 +81,106 @@ public function getValueFromStorageDataProvider()
];
}

public function testGetValueDefaultModeSaving()
{
/**
* $param bool $isUnexpectedValueExceptionThrown
* $param bool $isFileSystemExceptionThrown
* @dataProvider getValueDefaultModeDataProvider
*/
public function testGetValueDefaultMode(
$isUnexpectedValueExceptionThrown,
$isFileSystemExceptionThrown = null
) {
$versionType = 'integer';
$this->appState
$this->appStateMock
->expects($this->once())
->method('getMode')
->will($this->returnValue(\Magento\Framework\App\State::MODE_DEFAULT));
$storageException = new \UnexpectedValueException('Does not exist in the storage');
$this->versionStorage
->expects($this->once())
->method('load')
->will($this->throwException($storageException));
$this->versionStorage->expects($this->once())->method('save')->with($this->isType($versionType));
->willReturn(\Magento\Framework\App\State::MODE_DEFAULT);
if ($isUnexpectedValueExceptionThrown) {
$storageException = new \UnexpectedValueException('Does not exist in the storage');
$this->versionStorageMock
->expects($this->once())
->method('load')
->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->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],
];
}
}
62 changes: 48 additions & 14 deletions lib/internal/Magento/Framework/App/View/Deployment/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

namespace Magento\Framework\App\View\Deployment;

use Psr\Log\LoggerInterface;
use Magento\Framework\Exception\FileSystemException;

/**
* Deployment version of static files
*/
Expand All @@ -26,6 +29,11 @@ class Version
*/
private $cachedValue;

/**
* @var LoggerInterface
*/
private $logger;

/**
* @param \Magento\Framework\App\State $appState
* @param Version\StorageInterface $versionStorage
Expand Down Expand Up @@ -59,23 +67,49 @@ public function getValue()
*/
protected function readValue($appMode)
{
switch ($appMode) {
case \Magento\Framework\App\State::MODE_DEFAULT:
try {
$result = $this->versionStorage->load();
} catch (\UnexpectedValueException $e) {
$result = (new \DateTime())->getTimestamp();
$this->versionStorage->save($result);
if ($appMode == \Magento\Framework\App\State::MODE_DEVELOPER) {
$result = $this->generateVersion();
} else {
try {
$result = $this->versionStorage->load();
} catch (\UnexpectedValueException $e) {
$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();
break;
/**
* Generate version of static content
*
* @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 comments on commit 7003dff

Please sign in to comment.