Skip to content

Commit 3ce2926

Browse files
committed
MAGETWO-21072: Entry point responsiveness
- tests stabilization
1 parent 2618760 commit 3ce2926

File tree

7 files changed

+212
-47
lines changed

7 files changed

+212
-47
lines changed

dev/tests/unit/testsuite/Magento/Framework/App/View/Asset/Publisher/CopyTest.php renamed to dev/tests/unit/testsuite/Magento/Framework/App/View/Asset/MaterializationStrategy/CopyTest.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,20 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
namespace Magento\Framework\App\View\Asset\Publisher;
7+
namespace Magento\Framework\App\View\Asset\MaterializationStrategy;
88

99
class CopyTest extends \PHPUnit_Framework_TestCase
1010
{
11+
/**
12+
* @var Copy
13+
*/
14+
private $copyPublisher;
15+
16+
public function setUp()
17+
{
18+
$this->copyPublisher = new Copy;
19+
}
20+
1121
public function testPublishFile()
1222
{
1323
$rootDir = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\WriteInterface')
@@ -17,7 +27,6 @@ public function testPublishFile()
1727
$sourcePath = 'source/path/file';
1828
$destinationPath = 'destination/path/file';
1929

20-
$copyPublisher = new Copy;
2130
$rootDir->expects($this->once())
2231
->method('copyFile')
2332
->with(
@@ -26,6 +35,13 @@ public function testPublishFile()
2635
$targetDir
2736
)->willReturn(true);
2837

29-
$this->assertTrue($copyPublisher->publishFile($rootDir, $targetDir, $sourcePath, $destinationPath));
38+
$this->assertTrue($this->copyPublisher->publishFile($rootDir, $targetDir, $sourcePath, $destinationPath));
39+
}
40+
41+
public function testIsSupported()
42+
{
43+
$asset = $this->getMockBuilder('Magento\Framework\View\Asset\LocalInterface')
44+
->getMock();
45+
$this->assertTrue($this->copyPublisher->isSupported($asset));
3046
}
3147
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\App\View\Asset\MaterializationStrategy;
8+
9+
use Magento\Framework\ObjectManagerInterface;
10+
use Magento\Framework\View\Asset;
11+
12+
class FactoryTest extends \PHPUnit_Framework_TestCase
13+
{
14+
/**
15+
* @var ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
16+
*/
17+
private $objectManager;
18+
19+
public function setUp()
20+
{
21+
$this->objectManager = $this->getMockBuilder('Magento\Framework\ObjectManagerInterface')
22+
->setMethods([])
23+
->getMock();
24+
}
25+
26+
public function testCreateEmptyStrategies()
27+
{
28+
$asset = $this->getAsset();
29+
$copyStrategy = $this->getMockBuilder('Magento\Framework\App\View\Asset\MaterializationStrategy\Copy')
30+
->setMethods([])
31+
->getMock();
32+
$copyStrategy->expects($this->once())
33+
->method('isSupported')
34+
->with($asset)
35+
->willReturn(true);
36+
37+
$this->objectManager->expects($this->once())
38+
->method('get')
39+
->with(Factory::DEFAULT_STRATEGY)
40+
->willReturn($copyStrategy);
41+
42+
$factory = new Factory($this->objectManager, []);
43+
$this->assertSame($copyStrategy, $factory->create($asset));
44+
}
45+
46+
public function testCreateSupported()
47+
{
48+
$asset = $this->getAsset();
49+
$copyStrategy = $this->getMockBuilder('Magento\Framework\App\View\Asset\MaterializationStrategy\Copy')
50+
->setMethods([])
51+
->getMock();
52+
$copyStrategy->expects($this->once())
53+
->method('isSupported')
54+
->with($asset)
55+
->willReturn(false);
56+
57+
$supportedStrategy = $this->getMockBuilder('Magento\Framework\App\View\Asset\MaterializationStrategy\StrategyInterface')
58+
->setMethods([])
59+
->getMock();
60+
$supportedStrategy->expects($this->once())
61+
->method('isSupported')
62+
->with($asset)
63+
->willReturn(true);
64+
65+
$factory = new Factory($this->objectManager, [$copyStrategy, $supportedStrategy]);
66+
$this->assertSame($supportedStrategy, $factory->create($asset));
67+
}
68+
69+
public function testCreateException()
70+
{
71+
$asset = $this->getAsset();
72+
$copyStrategy = $this->getMockBuilder('Magento\Framework\App\View\Asset\MaterializationStrategy\Copy')
73+
->setMethods([])
74+
->getMock();
75+
$copyStrategy->expects($this->once())
76+
->method('isSupported')
77+
->with($asset)
78+
->willReturn(false);
79+
80+
$this->objectManager->expects($this->once())
81+
->method('get')
82+
->with(Factory::DEFAULT_STRATEGY)
83+
->willReturn($copyStrategy);
84+
85+
$factory = new Factory($this->objectManager, []);
86+
87+
$this->setExpectedException('LogicException', __('No materialization strategy is supported'));
88+
$factory->create($asset);
89+
}
90+
91+
/**
92+
* @return Asset\LocalInterface|\PHPUnit_Framework_MockObject_MockObject
93+
*/
94+
private function getAsset()
95+
{
96+
return $this->getMockBuilder('Magento\Framework\View\Asset\LocalInterface')
97+
->setMethods([])
98+
->getMock();
99+
}
100+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Framework\App\View\Asset\MaterializationStrategy;
8+
9+
use Magento\Framework\View\Asset;
10+
11+
class SymlinkTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/**
14+
* @var Symlink
15+
*/
16+
private $symlinkPublisher;
17+
18+
public function setUp()
19+
{
20+
$this->symlinkPublisher = new Symlink;
21+
}
22+
23+
public function testPublishFile()
24+
{
25+
$rootDir = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\WriteInterface')
26+
->getMock();
27+
$targetDir = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\WriteInterface')
28+
->getMock();
29+
$sourcePath = 'source/path/file';
30+
$destinationPath = 'destination/path/file';
31+
32+
$rootDir->expects($this->once())
33+
->method('createSymlink')
34+
->with(
35+
$sourcePath,
36+
$destinationPath,
37+
$targetDir
38+
)->willReturn(true);
39+
40+
$this->assertTrue($this->symlinkPublisher->publishFile($rootDir, $targetDir, $sourcePath, $destinationPath));
41+
}
42+
43+
/**
44+
* @dataProvider sourceFileDataProvider
45+
*/
46+
public function testIsSupported($path, $expectation)
47+
{
48+
$asset = $this->getMockBuilder('Magento\Framework\View\Asset\LocalInterface')
49+
->setMethods([])
50+
->getMock();
51+
$asset->expects($this->once())
52+
->method('getSourceFile')
53+
->willReturn($path);
54+
$this->assertEquals($expectation, $this->symlinkPublisher->isSupported($asset));
55+
}
56+
57+
/**
58+
* @return array
59+
*/
60+
public function sourceFileDataProvider()
61+
{
62+
return [
63+
['path/to/file', true],
64+
[Asset\Source::TMP_MATERIALIZATION_DIR . '/path/to/file', false]
65+
];
66+
}
67+
}

dev/tests/unit/testsuite/Magento/Framework/App/View/Asset/Publisher/SymlinkTest.php

Lines changed: 0 additions & 32 deletions
This file was deleted.

dev/tests/unit/testsuite/Magento/Framework/App/View/Asset/PublisherTest.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,21 @@ class PublisherTest extends \PHPUnit_Framework_TestCase
3737
private $object;
3838

3939
/**
40-
* @var Publisher\PublisherInterface |\PHPUnit_Framework_MockObject_MockObject
40+
* @var MaterializationStrategy\Factory |\PHPUnit_Framework_MockObject_MockObject
4141
*/
42-
private $publisherFile;
42+
private $materializationStrategyFactory;
4343

4444
protected function setUp()
4545
{
4646
$this->filesystem = $this->getMock('Magento\Framework\Filesystem', [], [], '', false);
47-
$this->publisherFile = $this->getMock(
48-
'Magento\Framework\App\View\Asset\Publisher\PublisherInterface',
47+
$this->materializationStrategyFactory = $this->getMock(
48+
'Magento\Framework\App\View\Asset\MaterializationStrategy\Factory',
4949
[],
5050
[],
5151
'',
5252
false
5353
);
54-
$this->object = new Publisher($this->filesystem, $this->publisherFile);
54+
$this->object = new Publisher($this->filesystem, $this->materializationStrategyFactory);
5555

5656
$this->rootDirWrite = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\WriteInterface');
5757
$this->staticDirRead = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\ReadInterface');
@@ -83,12 +83,23 @@ public function testPublish()
8383
->method('isExist')
8484
->with('some/file.ext')
8585
->will($this->returnValue(false));
86+
$materializationStrategy = $this->getMock(
87+
'Magento\Framework\App\View\Asset\MaterializationStrategy\StrategyInterface',
88+
[],
89+
[],
90+
'',
91+
false
92+
);
8693

8794
$this->rootDirWrite->expects($this->once())
8895
->method('getRelativePath')
8996
->with('/root/some/file.ext')
9097
->will($this->returnValue('some/file.ext'));
91-
$this->publisherFile->expects($this->once())
98+
$this->materializationStrategyFactory->expects($this->once())
99+
->method('create')
100+
->with($this->getAsset())
101+
->will($this->returnValue($materializationStrategy));
102+
$materializationStrategy->expects($this->once())
92103
->method('publishFile')
93104
->with($this->rootDirWrite, $this->staticDirWrite, 'some/file.ext', 'some/file.ext')
94105
->will($this->returnValue(true));

lib/internal/Magento/Framework/App/View/Asset/MaterializationStrategy/Copy.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ public function publishFile(
3434
*
3535
* @param Asset\LocalInterface $asset
3636
* @return bool
37+
*
38+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
3739
*/
3840
public function isSupported(Asset\LocalInterface $asset)
3941
{

lib/internal/Magento/Framework/App/View/Asset/MaterializationStrategy/Factory.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66

77
namespace Magento\Framework\App\View\Asset\MaterializationStrategy;
88

9+
use Magento\Framework\ObjectManagerInterface;
910
use Magento\Framework\View\Asset;
1011

1112
class Factory
1213
{
1314
/**
1415
* Object Manager instance
1516
*
16-
* @var \Magento\Framework\ObjectManagerInterface
17+
* @var ObjectManagerInterface
1718
*/
18-
protected $_objectManager;
19+
protected $objectManager;
1920

2021
/**
2122
* Strategies list
@@ -30,12 +31,12 @@ class Factory
3031
const DEFAULT_STRATEGY = 'Magento\Framework\App\View\Asset\MaterializationStrategy\Copy';
3132

3233
/**
33-
* @param \Magento\Framework\ObjectManagerInterface $objectManager
34+
* @param ObjectManagerInterface $objectManager
3435
* @param StrategyInterface[] $strategiesList
3536
*/
36-
public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager, $strategiesList = [])
37+
public function __construct(ObjectManagerInterface $objectManager, $strategiesList = [])
3738
{
38-
$this->_objectManager = $objectManager;
39+
$this->objectManager = $objectManager;
3940
$this->strategiesList = $strategiesList;
4041
}
4142

@@ -50,7 +51,7 @@ public function __construct(\Magento\Framework\ObjectManagerInterface $objectMan
5051
public function create(Asset\LocalInterface $asset)
5152
{
5253
if (empty($this->strategiesList)) {
53-
$this->strategiesList[] = $this->_objectManager->get(self::DEFAULT_STRATEGY);
54+
$this->strategiesList[] = $this->objectManager->get(self::DEFAULT_STRATEGY);
5455
}
5556

5657
foreach ($this->strategiesList as $strategy) {

0 commit comments

Comments
 (0)