Skip to content

Commit

Permalink
#21756: Static test fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
p-bystritsky committed Apr 17, 2019
1 parent c6affac commit 4d37719
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
19 changes: 10 additions & 9 deletions lib/internal/Magento/Framework/View/Asset/MergeStrategy/Direct.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
namespace Magento\Framework\View\Asset\MergeStrategy;

use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Math\Random;
use Magento\Framework\View\Asset;

/**
Expand All @@ -31,27 +33,27 @@ class Direct implements \Magento\Framework\View\Asset\MergeStrategyInterface
private $cssUrlResolver;

/**
* @var \Magento\Framework\Math\Random
* @var Random
*/
private $mathRandom;

/**
* @param \Magento\Framework\Filesystem $filesystem
* @param \Magento\Framework\View\Url\CssResolver $cssUrlResolver
* @param \Magento\Framework\Math\Random|null $mathRandom
* @param Random|null $mathRandom
*/
public function __construct(
\Magento\Framework\Filesystem $filesystem,
\Magento\Framework\View\Url\CssResolver $cssUrlResolver,
\Magento\Framework\Math\Random $mathRandom = null
Random $mathRandom = null
) {
$this->filesystem = $filesystem;
$this->cssUrlResolver = $cssUrlResolver;
$this->mathRandom = $mathRandom ?: \Magento\Framework\App\ObjectManager::getInstance()->get(\Magento\Framework\Math\Random::class);;
$this->mathRandom = $mathRandom ?: ObjectManager::getInstance()->get(Random::class);
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function merge(array $assetsToMerge, Asset\LocalInterface $resultAsset)
{
Expand All @@ -67,10 +69,9 @@ public function merge(array $assetsToMerge, Asset\LocalInterface $resultAsset)
/**
* Merge files together and modify content if needed
*
* @param \Magento\Framework\View\Asset\MergeableInterface[] $assetsToMerge
* @param \Magento\ Framework\View\Asset\LocalInterface $resultAsset
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
* @param array $assetsToMerge
* @param Asset\LocalInterface $resultAsset
* @return array|string
*/
private function composeMergedContent(array $assetsToMerge, Asset\LocalInterface $resultAsset)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
*/
namespace Magento\Framework\View\Test\Unit\Asset\MergeStrategy;

use Magento\Framework\Filesystem\Directory\WriteInterface;
use \Magento\Framework\View\Asset\MergeStrategy\Direct;

use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Filesystem\Directory\WriteInterface;
use Magento\Framework\View\Asset\MergeStrategy\Direct;

/**
* Test for Magento\Framework\View\Asset\MergeStrategy\Direct.
*/
class DirectTest extends \PHPUnit\Framework\TestCase
{
/**
Expand Down Expand Up @@ -69,7 +71,8 @@ public function testMergeNoAssets()
->method('getUniqueHash')
->willReturn($uniqId);
$this->tmpDir->expects($this->once())->method('writeFile')->with('foo/result' . $uniqId, '');
$this->tmpDir->expects($this->once())->method('renameFile')->with('foo/result' . $uniqId, 'foo/result', $this->staticDir);
$this->tmpDir->expects($this->once())->method('renameFile')
->with('foo/result' . $uniqId, 'foo/result', $this->staticDir);
$this->object->merge([], $this->resultAsset);
}

Expand All @@ -83,7 +86,8 @@ public function testMergeGeneric()
->method('getUniqueHash')
->willReturn($uniqId);
$this->tmpDir->expects($this->once())->method('writeFile')->with('foo/result' . $uniqId, 'onetwo');
$this->tmpDir->expects($this->once())->method('renameFile')->with('foo/result' . $uniqId, 'foo/result', $this->staticDir);
$this->tmpDir->expects($this->once())->method('renameFile')
->with('foo/result' . $uniqId, 'foo/result', $this->staticDir);
$this->object->merge($assets, $this->resultAsset);
}

Expand All @@ -92,7 +96,7 @@ public function testMergeCss()
$uniqId = '_f929c374767e00712449660ea673f2f5';
$this->resultAsset->expects($this->exactly(3))
->method('getPath')
->will($this->returnValue('foo/result'));
->willReturn('foo/result');
$this->resultAsset->expects($this->any())->method('getContentType')->will($this->returnValue('css'));
$assets = $this->prepareAssetsToMerge(['one', 'two']);
$this->cssUrlResolver->expects($this->exactly(2))
Expand All @@ -101,13 +105,14 @@ public function testMergeCss()
$this->cssUrlResolver->expects($this->once())
->method('aggregateImportDirectives')
->with('12')
->will($this->returnValue('1020'));
->willReturn('1020');
$this->mathRandomMock->expects($this->once())
->method('getUniqueHash')
->willReturn($uniqId);
$this->staticDir->expects($this->never())->method('writeFile');
$this->tmpDir->expects($this->once())->method('writeFile')->with('foo/result' . $uniqId, '1020');
$this->tmpDir->expects($this->once())->method('renameFile')->with('foo/result' . $uniqId, 'foo/result', $this->staticDir);
$this->tmpDir->expects($this->once())->method('renameFile')
->with('foo/result' . $uniqId, 'foo/result', $this->staticDir);
$this->object->merge($assets, $this->resultAsset);
}

Expand Down

0 comments on commit 4d37719

Please sign in to comment.