Skip to content

Commit

Permalink
Merge remote-tracking branch 'github/develop' into public-pulls
Browse files Browse the repository at this point in the history
  • Loading branch information
vpelipenko committed Jan 16, 2015
2 parents e8fd092 + 313019d commit 5cb5b9c
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Ui/DataProvider/Config/FileResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function get($filename, $scope)
{
$iterator = $this->iteratorFactory->create(
$this->directoryRead,
$this->directoryRead->search('/*/*/etc/data_source/*')
$this->directoryRead->search('/*/*/etc/data_source/' . $filename)
);
return $iterator;
}
Expand Down
3 changes: 3 additions & 0 deletions dev/shell/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,20 @@

$usage = 'Usage: php -f cache.php -- [--' . ManagerApp::KEY_SET . '=1|0]'
. ' [--' . ManagerApp::KEY_CLEAN . ']'
. ' [--' . ManagerApp::KEY_STATUS . ']'
. ' [--' . ManagerApp::KEY_FLUSH . ']'
. ' [--' . ManagerApp::KEY_TYPES . '=<type1>,<type2>,...]'
. ' [--bootstrap=' . escapeshellarg('INIT_PARAM=foo&ANOTHER_PARAM[key]=bar') . ']
--' . ManagerApp::KEY_TYPES . ' - list of cache types, comma-separated. If omitted, all caches will be affected
--' . ManagerApp::KEY_SET . ' - enable or disable the specified cache types
--' . ManagerApp::KEY_CLEAN . ' - clean data of the specified cache types
--' . ManagerApp::KEY_STATUS . ' - display current status for each cache type
--' . ManagerApp::KEY_FLUSH . ' - destroy all data in storage that the specified cache types reside on
--bootstrap - add or override parameters of the bootstrap' . PHP_EOL;
$longOpts = [
ManagerApp::KEY_SET . '::',
ManagerApp::KEY_CLEAN,
ManagerApp::KEY_STATUS,
ManagerApp::KEY_FLUSH,
ManagerApp::KEY_TYPES . '::',
'bootstrap::',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ protected function setUp()

public function testLaunchStatus()
{
$requestArgs = [
ManagerApp::KEY_STATUS => true
];

$this->response->expects($this->once())
->method('setBody')
->with(
$this->matches("Current status:%afoo: 1%abar: 1%abaz: 0")
);

$model = new ManagerApp($this->cacheManager, $this->response, []);
$model = new ManagerApp($this->cacheManager, $this->response, $requestArgs);
$model->launch();
}

Expand All @@ -58,7 +62,7 @@ public function testLaunchEnable()
$this->response->expects($this->once())
->method('setBody')
->with(
$this->matches("Changed cache status:%abaz: 0 -> 1%aCleaned cache types: baz%a")
$this->matches("Changed cache status:\n%abaz: 0 -> 1\nCleaned cache types:\nbaz")
);

$model = new ManagerApp($this->cacheManager, $this->response, $requestArgs);
Expand All @@ -80,7 +84,7 @@ public function testLaunchDisable()
$this->response->expects($this->once())
->method('setBody')
->with(
$this->matches("Changed cache status:%abaz: 1 -> 0%a%a")
$this->matches("Changed cache status:\n%abaz: 1 -> 0\n")
);

$model = new ManagerApp($this->cacheManager, $this->response, $requestArgs);
Expand All @@ -103,7 +107,7 @@ public function testLaunchFlush()
$this->response->expects($this->once())
->method('setBody')
->with(
$this->matches("Flushed cache types: foo, bar%a")
$this->matches("Flushed cache types:\nfoo\nbar")
);

$model = new ManagerApp($this->cacheManager, $this->response, $requestArgs);
Expand All @@ -126,7 +130,7 @@ public function testLaunchClean()
$this->response->expects($this->once())
->method('setBody')
->with(
$this->matches("Cleaned cache types: foo, bar%a")
$this->matches("Cleaned cache types:\nfoo\nbar")
);

$model = new ManagerApp($this->cacheManager, $this->response, $requestArgs);
Expand All @@ -152,7 +156,7 @@ public function testLaunchSetAndClean()
$this->response->expects($this->once())
->method('setBody')
->with(
$this->matches("Changed cache status:%afoo: 0 -> 1%aCleaned cache types: foo, bar%a")
$this->matches("Changed cache status:\n%afoo: 0 -> 1\nCleaned cache types:\nfoo\nbar")
);

$model = new ManagerApp($this->cacheManager, $this->response, $requestArgs);
Expand All @@ -179,7 +183,7 @@ public function testLaunchAll()
$this->response->expects($this->once())
->method('setBody')
->with(
$this->matches("Changed cache status:%abaz: 0 -> 1%aFlushed cache types: foo, baz%a")
$this->matches("Changed cache status:\n%abaz: 0 -> 1%aFlushed cache types:\nfoo\nbaz")
);

$model = new ManagerApp($this->cacheManager, $this->response, $requestArgs);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Magento\Ui\DataProvider\Config;

use Magento\Framework\Filesystem;
use Magento\Ui\DataProvider\Config\FileResolver;
use Magento\Framework\Config\FileIteratorFactory;

class FileResolverTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Magento\Framework\Filesystem\Directory\Read | \PHPUnit_Framework_MockObject_MockObject
*/
private $mockDirectoryRead;

/**
* @var FileResolver
*/
private $fileResolver;

public function setUp()
{
$this->mockDirectoryRead = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\Read')
->disableOriginalConstructor()
->getMock();
$stubFileIteratorFactory = $this->getMockBuilder('Magento\Framework\Config\FileIteratorFactory')
->disableOriginalConstructor()
->getMock();
$stubFilesystem = $this->getMockBuilder('Magento\Framework\Filesystem')
->disableOriginalConstructor()
->getMock();
$stubFilesystem->expects($this->any())
->method('getDirectoryRead')
->willReturn($this->mockDirectoryRead);
$this->fileResolver = new FileResolver($stubFilesystem, $stubFileIteratorFactory);
}

public function testItAppliesTheFilenamePattern()
{
$this->mockDirectoryRead->expects($this->once())
->method('search')
->with($this->matchesRegularExpression('#\*\.xml$#'))
->willReturn([]);

$this->fileResolver->get('*.xml', '');
}
}
21 changes: 14 additions & 7 deletions lib/internal/Magento/Framework/App/Cache/ManagerApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ManagerApp implements AppInterface
const KEY_SET = 'set';
const KEY_CLEAN = 'clean';
const KEY_FLUSH = 'flush';
const KEY_STATUS = 'status';
/**#@- */

/**
Expand Down Expand Up @@ -89,18 +90,24 @@ public function launch()
}
if (isset($this->requestArgs[self::KEY_FLUSH])) {
$this->cacheManager->flush($types);
$output[] = 'Flushed cache types: ' . join(', ', $types);
$output[] = 'Flushed cache types:';
$output[] = join("\n", $types);
} elseif (isset($this->requestArgs[self::KEY_CLEAN])) {
$this->cacheManager->clean($types);
$output[] = 'Cleaned cache types: ' . join(', ', $types);
$output[] = 'Cleaned cache types:';
$output[] = join("\n", $types);
} elseif (isset($this->requestArgs[self::KEY_STATUS])) {
$output[] = 'Current status:';
foreach ($this->cacheManager->getStatus() as $cache => $status) {
$output[] = sprintf('%30s: %d', $cache, $status);
}
} elseif (!empty($enabledTypes)) {
$this->cacheManager->clean($enabledTypes);
$output[] = 'Cleaned cache types: ' . join(', ', $enabledTypes);
}
$output[] = 'Current status:';
foreach ($this->cacheManager->getStatus() as $cache => $status) {
$output[] = sprintf('%30s: %d', $cache, $status);
$output[] = 'Cleaned cache types:';
$output[] = join("\n", $enabledTypes);
}

$output[] = '';
$this->response->setBody(join("\n", $output));
return $this->response;
}
Expand Down

0 comments on commit 5cb5b9c

Please sign in to comment.