-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #591 from magento-ogre/PR_Branch
[Ogres] Bug Fixes
- Loading branch information
Showing
33 changed files
with
1,085 additions
and
438 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Framework\Code; | ||
|
||
use Magento\Framework\App\Filesystem\DirectoryList; | ||
use Magento\Framework\Filesystem\Directory\WriteFactory; | ||
use Magento\Framework\Filesystem\Directory\WriteInterface; | ||
|
||
/** | ||
* Regenerates generated code and DI configuration | ||
*/ | ||
class GeneratedFiles | ||
{ | ||
/** | ||
* Separator literal to assemble timer identifier from timer names | ||
*/ | ||
const REGENERATE_FLAG = '/var/.regenerate'; | ||
|
||
/** | ||
* @var DirectoryList | ||
*/ | ||
private $directoryList; | ||
|
||
/** | ||
* @var WriteInterface | ||
*/ | ||
private $write; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param DirectoryList $directoryList | ||
* @param WriteFactory $writeFactory | ||
*/ | ||
public function __construct(DirectoryList $directoryList, WriteFactory $writeFactory) | ||
{ | ||
$this->directoryList = $directoryList; | ||
$this->write = $writeFactory->create(BP); | ||
} | ||
|
||
/** | ||
* Clean generated code and DI configuration | ||
* | ||
* @return void | ||
*/ | ||
public function regenerate() | ||
{ | ||
if ($this->write->isExist(self::REGENERATE_FLAG)) { | ||
$generationPath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::GENERATION)); | ||
$diPath = $this->write->getRelativePath($this->directoryList->getPath(DirectoryList::DI)); | ||
|
||
if ($this->write->isDirectory($generationPath)) { | ||
$this->write->delete($generationPath); | ||
} | ||
if ($this->write->isDirectory($diPath)) { | ||
$this->write->delete($diPath); | ||
} | ||
$this->write->delete(self::REGENERATE_FLAG); | ||
} | ||
} | ||
|
||
/** | ||
* Create flag for regeneration of code and di | ||
* | ||
* @return void | ||
*/ | ||
public function requestRegeneration() | ||
{ | ||
$this->write->touch(self::REGENERATE_FLAG); | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
lib/internal/Magento/Framework/Code/Test/Unit/GeneratedFilesTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
/** | ||
* Copyright © 2016 Magento. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Framework\Code\Test\Unit; | ||
|
||
use Magento\Framework\App\Filesystem\DirectoryList; | ||
use Magento\Framework\Code\GeneratedFiles; | ||
|
||
class GeneratedFilesTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* @var Magento\Framework\App\Filesystem\DirectoryList | \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $directoryList; | ||
|
||
/** | ||
* @var Magento\Framework\Filesystem\Directory\WriteInterface | \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $writeInterface; | ||
|
||
/** | ||
* @var \Magento\Framework\Code\GeneratedFiles | ||
*/ | ||
private $model; | ||
|
||
protected function setUp() | ||
{ | ||
$this->directoryList = $this->getMock('\Magento\Framework\App\Filesystem\DirectoryList', [], [], '', false); | ||
$writeFactory = $this->getMock('\Magento\Framework\Filesystem\Directory\WriteFactory', [], [], '', false); | ||
$this->writeInterface = $this->getMock( | ||
'\Magento\Framework\Filesystem\Directory\WriteInterface', | ||
[], | ||
[], | ||
'', | ||
false | ||
); | ||
$writeFactory->expects($this->once())->method('create')->willReturn($this->writeInterface); | ||
$this->model = new GeneratedFiles($this->directoryList, $writeFactory); | ||
} | ||
|
||
/** | ||
* @param array $getPathMap | ||
* @param array $isDirectoryMap | ||
* @param array $deleteMap | ||
* @dataProvider regenerateDataProvider | ||
*/ | ||
public function testRegenerate($getPathMap, $isDirectoryMap, $deleteMap) | ||
{ | ||
|
||
$this->writeInterface | ||
->expects($this->once()) | ||
->method('isExist') | ||
->with(GeneratedFiles::REGENERATE_FLAG) | ||
->willReturn(true); | ||
$this->directoryList->expects($this->exactly(2))->method('getPath')->willReturnMap($getPathMap); | ||
$this->writeInterface->expects($this->exactly(2))->method('getRelativePath')->willReturnMap($getPathMap); | ||
$this->writeInterface->expects($this->exactly(2))->method('isDirectory')->willReturnMap($isDirectoryMap); | ||
$this->writeInterface->expects($this->exactly(1))->method('delete')->willReturnMap($deleteMap); | ||
$this->model->regenerate(); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function regenerateDataProvider() | ||
{ | ||
$pathToGeneration = 'path/to/generation'; | ||
$pathToDi = 'path/to/di'; | ||
|
||
$getPathMap = [[DirectoryList::GENERATION, $pathToGeneration], | ||
[DirectoryList::DI, $pathToDi]]; | ||
$deleteMap = [[BP . '/' . $pathToGeneration, true], | ||
[BP . '/' . $pathToDi, true], | ||
[BP . GeneratedFiles::REGENERATE_FLAG, true], | ||
]; | ||
|
||
return [ | ||
'runAll' => [ $getPathMap, [[BP . '/' . $pathToGeneration, true], | ||
[BP . '/' . $pathToDi, true]], $deleteMap ], | ||
'noDIfolder' => [ $getPathMap, [[BP . '/' . $pathToGeneration, true], | ||
[BP . '/' . $pathToDi, false]], $deleteMap], | ||
'noGenerationfolder' => [$getPathMap, [[BP . '/' . $pathToGeneration, false], | ||
[BP . '/' . $pathToDi, true]], $deleteMap], | ||
'nofolders' => [ $getPathMap, [[BP . '/' . $pathToGeneration, false], | ||
[BP . '/' . $pathToDi, false]], $deleteMap], | ||
]; | ||
} | ||
|
||
public function testRegenerateWithNoFlag() | ||
{ | ||
$this->writeInterface | ||
->expects($this->once()) | ||
->method('isExist') | ||
->with(GeneratedFiles::REGENERATE_FLAG) | ||
->willReturn(false); | ||
$this->directoryList->expects($this->never())->method('getPath'); | ||
$this->writeInterface->expects($this->never())->method('getPath'); | ||
$this->writeInterface->expects($this->never())->method('delete'); | ||
$this->model->regenerate(); | ||
} | ||
|
||
public function testRequestRegeneration() | ||
{ | ||
$this->writeInterface->expects($this->once())->method("touch"); | ||
$this->model->requestRegeneration(); | ||
} | ||
} |
Oops, something went wrong.