Skip to content

Commit 85f422f

Browse files
committed
MAGETWO-21072: Entry point responsiveness
- added tests - broke dependencies
1 parent 822f737 commit 85f422f

File tree

12 files changed

+254
-66
lines changed

12 files changed

+254
-66
lines changed

app/etc/di.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,11 +463,18 @@
463463
<argument name="stateCollection" xsi:type="object" shared="false">Magento\Framework\Mview\View\State\CollectionInterface</argument>
464464
</arguments>
465465
</type>
466+
<type name="Magento\Framework\App\View\Asset\Publisher" shared="false" />
466467
<type name="Magento\Framework\App\StaticResource">
467468
<arguments>
468469
<argument name="response" xsi:type="object" shared="false">Magento\Core\Model\File\Storage\Response</argument>
470+
<argument name="publisher" xsi:type="object">symlinkPublisher</argument>
469471
</arguments>
470472
</type>
473+
<virtualType name="symlinkPublisher" type="Magento\Framework\App\View\Asset\Publisher">
474+
<arguments>
475+
<argument name="publisher" xsi:type="object">Magento\Framework\App\View\Asset\Publisher\Symlink</argument>
476+
</arguments>
477+
</virtualType>
471478
<virtualType name="fallbackResolverSimpleWithGroupedCache" type="Magento\Framework\View\Design\FileResolution\Fallback\Resolver\Simple">
472479
<arguments>
473480
<argument name="cache" xsi:type="object">Magento\Framework\View\Design\FileResolution\Fallback\CacheData\Grouped</argument>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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\Publisher;
8+
9+
class CopyTest extends \PHPUnit_Framework_TestCase
10+
{
11+
public function testPublishFile()
12+
{
13+
$rootDir = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\WriteInterface')
14+
->getMock();
15+
$targetDir = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\WriteInterface')
16+
->getMock();
17+
$sourcePath = 'source/path/file';
18+
$destinationPath = 'destination/path/file';
19+
20+
$copyPublisher = new Copy;
21+
$rootDir->expects($this->once())
22+
->method('copyFile')
23+
->with(
24+
$sourcePath,
25+
$destinationPath,
26+
$targetDir
27+
)->willReturn(true);
28+
29+
$this->assertTrue($copyPublisher->publishFile($rootDir, $targetDir, $sourcePath, $destinationPath));
30+
}
31+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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\Publisher;
8+
9+
10+
class SymlinkTest extends \PHPUnit_Framework_TestCase
11+
{
12+
public function testPublishFile()
13+
{
14+
$rootDir = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\WriteInterface')
15+
->getMock();
16+
$targetDir = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\WriteInterface')
17+
->getMock();
18+
$sourcePath = 'source/path/file';
19+
$destinationPath = 'destination/path/file';
20+
21+
$copyPublisher = new Symlink;
22+
$rootDir->expects($this->once())
23+
->method('createSymlink')
24+
->with(
25+
$sourcePath,
26+
$destinationPath,
27+
$targetDir
28+
)->willReturn(true);
29+
30+
$this->assertTrue($copyPublisher->publishFile($rootDir, $targetDir, $sourcePath, $destinationPath));
31+
}
32+
}

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

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@
1111

1212
class PublisherTest extends \PHPUnit_Framework_TestCase
1313
{
14-
/**
15-
* @var \Magento\Framework\App\State|\PHPUnit_Framework_MockObject_MockObject
16-
*/
17-
private $appState;
18-
1914
/**
2015
* @var \Magento\Framework\Filesystem|\PHPUnit_Framework_MockObject_MockObject
2116
*/
@@ -41,11 +36,22 @@ class PublisherTest extends \PHPUnit_Framework_TestCase
4136
*/
4237
private $object;
4338

39+
/**
40+
* @var Publisher\PublisherInterface |\PHPUnit_Framework_MockObject_MockObject
41+
*/
42+
private $publisherFile;
43+
4444
protected function setUp()
4545
{
46-
$this->appState = $this->getMock('Magento\Framework\App\State', [], [], '', false);
4746
$this->filesystem = $this->getMock('Magento\Framework\Filesystem', [], [], '', false);
48-
$this->object = new Publisher($this->appState, $this->filesystem);
47+
$this->publisherFile = $this->getMock(
48+
'Magento\Framework\App\View\Asset\Publisher\PublisherInterface',
49+
[],
50+
[],
51+
'',
52+
false
53+
);
54+
$this->object = new Publisher($this->filesystem, $this->publisherFile);
4955

5056
$this->rootDirWrite = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\WriteInterface');
5157
$this->staticDirRead = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\ReadInterface');
@@ -62,19 +68,8 @@ protected function setUp()
6268
]));
6369
}
6470

65-
public function testPublishNotAllowed()
66-
{
67-
$this->appState->expects($this->once())
68-
->method('getMode')
69-
->will($this->returnValue(\Magento\Framework\App\State::MODE_DEVELOPER));
70-
$this->assertFalse($this->object->publish($this->getAsset()));
71-
}
72-
7371
public function testPublishExistsBefore()
7472
{
75-
$this->appState->expects($this->once())
76-
->method('getMode')
77-
->will($this->returnValue(\Magento\Framework\App\State::MODE_PRODUCTION));
7873
$this->staticDirRead->expects($this->once())
7974
->method('isExist')
8075
->with('some/file.ext')
@@ -84,9 +79,6 @@ public function testPublishExistsBefore()
8479

8580
public function testPublish()
8681
{
87-
$this->appState->expects($this->once())
88-
->method('getMode')
89-
->will($this->returnValue(\Magento\Framework\App\State::MODE_PRODUCTION));
9082
$this->staticDirRead->expects($this->once())
9183
->method('isExist')
9284
->with('some/file.ext')
@@ -96,9 +88,9 @@ public function testPublish()
9688
->method('getRelativePath')
9789
->with('/root/some/file.ext')
9890
->will($this->returnValue('some/file.ext'));
99-
$this->rootDirWrite->expects($this->once())
100-
->method('copyFile')
101-
->with('some/file.ext', 'some/file.ext', $this->staticDirWrite)
91+
$this->publisherFile->expects($this->once())
92+
->method('publishFile')
93+
->with($this->rootDirWrite, $this->staticDirWrite, 'some/file.ext', 'some/file.ext')
10294
->will($this->returnValue(true));
10395

10496
$this->assertTrue($this->object->publish($this->getAsset()));

dev/tests/unit/testsuite/Magento/Framework/Filesystem/Directory/WriteTest.php

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ class WriteTest extends \PHPUnit_Framework_TestCase
2828
*/
2929
protected $fileFactory;
3030

31+
/**
32+
* @var string
33+
*/
34+
protected $path;
35+
3136
/**
3237
* Set up
3338
*/
@@ -41,10 +46,11 @@ protected function setUp()
4146
'',
4247
false
4348
);
49+
$this->path = 'PATH/';
4450
$this->write = new \Magento\Framework\Filesystem\Directory\Write(
4551
$this->fileFactory,
4652
$this->driver,
47-
null,
53+
$this->path,
4854
'cool-permissions'
4955
);
5056
}
@@ -81,4 +87,66 @@ public function testIsWritable()
8187
$this->driver->expects($this->once())->method('isWritable')->will($this->returnValue(true));
8288
$this->assertTrue($this->write->isWritable('correct-path'));
8389
}
90+
91+
92+
public function testCreateSymlinkTargetDirectoryExists()
93+
{
94+
$targetDir = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\WriteInterface')
95+
->getMock();
96+
$targetDir->driver = $this->driver;
97+
$sourcePath = 'source/path/file';
98+
$destinationDirectory = 'destination/path';
99+
$destinationFile = $destinationDirectory . '/' . 'file';
100+
101+
$this->assertIsFileExpectation($sourcePath);
102+
$this->driver->expects($this->once())
103+
->method('getParentDirectory')
104+
->with($destinationFile)
105+
->willReturn($destinationDirectory);
106+
$targetDir->expects($this->once())
107+
->method('isExist')
108+
->with($destinationDirectory)
109+
->willReturn(true);
110+
$targetDir->expects($this->once())
111+
->method('getAbsolutePath')
112+
->with($destinationFile)
113+
->willReturn($this->getAbsolutePath($destinationFile));
114+
$this->driver->expects($this->once())
115+
->method('symlink')
116+
->with(
117+
$this->getAbsolutePath($sourcePath),
118+
$this->getAbsolutePath($destinationFile),
119+
$targetDir->driver
120+
)->willReturn(true);
121+
122+
$this->assertTrue($this->write->createSymlink($sourcePath, $destinationFile, $targetDir));
123+
}
124+
125+
/**
126+
* Assert is file expectation
127+
*
128+
* @param string $path
129+
*/
130+
private function assertIsFileExpectation($path)
131+
{
132+
$this->driver->expects($this->any())
133+
->method('getAbsolutePath')
134+
->with($this->path, $path)
135+
->willReturn($this->getAbsolutePath($path));
136+
$this->driver->expects($this->any())
137+
->method('isFile')
138+
->with($this->getAbsolutePath($path))
139+
->willReturn(true);
140+
}
141+
142+
/**
143+
* Returns expected absolute path to file
144+
*
145+
* @param string $path
146+
* @return string
147+
*/
148+
private function getAbsolutePath($path)
149+
{
150+
return $this->path . $path;
151+
}
84152
}

dev/tools/Magento/Tools/View/Deployer.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Framework\App\ObjectManagerFactory;
1010
use Magento\Framework\App\View\Deployment\Version;
1111
use Magento\Framework\Test\Utility\Files;
12+
use Magento\Framework\App\View\Asset\Publisher;
1213

1314
/**
1415
* A service for deploying Magento static view files for production mode
@@ -35,7 +36,7 @@ class Deployer
3536
/** @var \Magento\Framework\View\Asset\Repository */
3637
private $assetRepo;
3738

38-
/** @var \Magento\Framework\App\View\Asset\Publisher */
39+
/** @var Publisher */
3940
private $assetPublisher;
4041

4142
/** @var bool */
@@ -170,7 +171,11 @@ private function emulateApplicationArea($areaCode)
170171
$configLoader = $objectManager->get('Magento\Framework\App\ObjectManager\ConfigLoader');
171172
$objectManager->configure($configLoader->load($areaCode));
172173
$this->assetRepo = $objectManager->get('Magento\Framework\View\Asset\Repository');
173-
$this->assetPublisher = $objectManager->get('Magento\Framework\App\View\Asset\Publisher');
174+
175+
$this->assetPublisher = $objectManager->create(
176+
'Magento\Framework\App\View\Asset\Publisher',
177+
['publisher' => new Publisher\Copy()]
178+
);
174179
}
175180

176181
/**

lib/internal/Magento/Framework/App/StaticResource.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class StaticResource implements \Magento\Framework\AppInterface
3030
private $request;
3131

3232
/**
33-
* @var View\Asset\Publisher\Symlink
33+
* @var View\Asset\Publisher
3434
*/
3535
private $publisher;
3636

@@ -62,7 +62,7 @@ class StaticResource implements \Magento\Framework\AppInterface
6262
* @param State $state
6363
* @param Response\FileInterface $response
6464
* @param Request\Http $request
65-
* @param View\Asset\Publisher\Symlink $publisher
65+
* @param View\Asset\Publisher $publisher
6666
* @param \Magento\Framework\View\Asset\Repository $assetRepo
6767
* @param \Magento\Framework\Module\ModuleList $moduleList
6868
* @param \Magento\Framework\ObjectManagerInterface $objectManager
@@ -73,7 +73,7 @@ public function __construct(
7373
State $state,
7474
Response\FileInterface $response,
7575
Request\Http $request,
76-
View\Asset\Publisher\Symlink $publisher,
76+
View\Asset\Publisher $publisher,
7777
\Magento\Framework\View\Asset\Repository $assetRepo,
7878
\Magento\Framework\Module\ModuleList $moduleList,
7979
\Magento\Framework\ObjectManagerInterface $objectManager,

lib/internal/Magento/Framework/App/View/Asset/Publisher.php

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,32 @@
88

99
use Magento\Framework\App\Filesystem\DirectoryList;
1010
use Magento\Framework\View\Asset;
11-
use Magento\Framework\Filesystem\Directory\WriteInterface;
1211

1312
/**
1413
* A publishing service for view assets
1514
*/
1615
class Publisher
1716
{
1817
/**
19-
* @var \Magento\Framework\App\State
18+
* @var \Magento\Framework\Filesystem
2019
*/
21-
protected $appState;
20+
protected $filesystem;
2221

2322
/**
24-
* @var \Magento\Framework\Filesystem
23+
* @var Publisher\PublisherInterface
2524
*/
26-
protected $filesystem;
25+
private $publisher;
2726

2827
/**
29-
* @param \Magento\Framework\App\State $appState
3028
* @param \Magento\Framework\Filesystem $filesystem
29+
* @param Publisher\PublisherInterface $publisher
3130
*/
3231
public function __construct(
33-
\Magento\Framework\App\State $appState,
34-
\Magento\Framework\Filesystem $filesystem
32+
\Magento\Framework\Filesystem $filesystem,
33+
Publisher\PublisherInterface $publisher
3534
) {
36-
$this->appState = $appState;
3735
$this->filesystem = $filesystem;
36+
$this->publisher = $publisher;
3837
}
3938

4039
/**
@@ -47,28 +46,21 @@ public function publish(Asset\LocalInterface $asset)
4746
return true;
4847
}
4948

50-
$rootDir = $this->filesystem->getDirectoryWrite(DirectoryList::ROOT);
51-
$source = $rootDir->getRelativePath($asset->getSourceFile());
52-
53-
return $this->publishFile(
54-
$rootDir,
55-
$source,
56-
$asset->getPath(),
57-
$this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW)
58-
);
49+
return $this->publishAsset($asset);
5950
}
6051

6152
/**
62-
* Publish file
53+
* Publish the asset
6354
*
64-
* @param WriteInterface $rootDir
65-
* @param string $source
66-
* @param string $destination
67-
* @param WriteInterface $dir
55+
* @param Asset\LocalInterface $asset
6856
* @return bool
6957
*/
70-
protected function publishFile($rootDir, $source, $destination, $dir)
58+
private function publishAsset(Asset\LocalInterface $asset)
7159
{
72-
return $rootDir->copyFile($source, $destination, $dir);
60+
$targetDir = $this->filesystem->getDirectoryWrite(DirectoryList::STATIC_VIEW);
61+
$rootDir = $this->filesystem->getDirectoryWrite(DirectoryList::ROOT);
62+
$source = $rootDir->getRelativePath($asset->getSourceFile());
63+
$destination = $asset->getPath();
64+
return $this->publisher->publishFile($rootDir, $targetDir, $source, $destination);
7365
}
7466
}

0 commit comments

Comments
 (0)