Skip to content

Commit dd47569

Browse files
author
Kopylova,Olga(okopylova)
committed
Merge pull request #520 from magento-ogre/PR_Branch
[Ogres] Bug Fixes
2 parents 2dff306 + d8f8547 commit dd47569

File tree

257 files changed

+949
-3277
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

257 files changed

+949
-3277
lines changed

app/code/Magento/Backend/Console/Command/AbstractCacheManageCommand.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
use Symfony\Component\Console\Input\InputArgument;
1010
use Symfony\Component\Console\Input\InputInterface;
11-
use Symfony\Component\Console\Input\InputOption;
1211

1312
abstract class AbstractCacheManageCommand extends AbstractCacheCommand
1413
{
@@ -17,11 +16,6 @@ abstract class AbstractCacheManageCommand extends AbstractCacheCommand
1716
*/
1817
const INPUT_KEY_TYPES = 'types';
1918

20-
/**
21-
* Input key all
22-
*/
23-
const INPUT_KEY_ALL = 'all';
24-
2519
/**
2620
* {@inheritdoc}
2721
*/
@@ -30,18 +24,11 @@ protected function configure()
3024
$this->addArgument(
3125
self::INPUT_KEY_TYPES,
3226
InputArgument::IS_ARRAY,
33-
'List of cache types, space separated. If omitted, all caches will be affected'
34-
);
35-
$this->addOption(
36-
self::INPUT_KEY_ALL,
37-
null,
38-
InputOption::VALUE_NONE,
39-
'All cache types'
27+
'Space-separated list of cache types or omit to apply to all cache types.'
4028
);
4129
parent::configure();
4230
}
4331

44-
4532
/**
4633
* Get requested cache types
4734
*
@@ -56,7 +43,7 @@ protected function getRequestedTypes(InputInterface $input)
5643
$requestedTypes = array_filter(array_map('trim', $requestedTypes), 'strlen');
5744
}
5845
if (empty($requestedTypes)) {
59-
return [];
46+
return $this->cacheManager->getAvailableTypes();
6047
} else {
6148
$availableTypes = $this->cacheManager->getAvailableTypes();
6249
$unsupportedTypes = array_diff($requestedTypes, $availableTypes);

app/code/Magento/Backend/Console/Command/AbstractCacheSetCommand.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ abstract protected function isEnable();
2424
protected function execute(InputInterface $input, OutputInterface $output)
2525
{
2626
$isEnable = $this->isEnable();
27-
if ($input->getOption(self::INPUT_KEY_ALL)) {
28-
$types = $this->cacheManager->getAvailableTypes();
29-
} else {
30-
$types = $this->getRequestedTypes($input);
31-
}
27+
$types = $this->getRequestedTypes($input);
3228
$changedTypes = $this->cacheManager->setEnabled($types, $isEnable);
3329
if ($changedTypes) {
3430
$output->writeln('Changed cache status:');

app/code/Magento/Backend/Console/Command/AbstractCacheTypeManageCommand.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,7 @@ abstract protected function getDisplayMessage();
3535
*/
3636
protected function execute(InputInterface $input, OutputInterface $output)
3737
{
38-
if ($input->getOption(self::INPUT_KEY_ALL)) {
39-
$types = $this->cacheManager->getAvailableTypes();
40-
} else {
41-
$types = $this->getRequestedTypes($input);
42-
}
38+
$types = $this->getRequestedTypes($input);
4339
$this->performAction($types);
4440
$output->writeln($this->getDisplayMessage());
4541
$output->writeln(join(PHP_EOL, $types));
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Backend\Test\Unit\Console\Command;
8+
9+
use Magento\Backend\Console\Command\AbstractCacheManageCommand;
10+
11+
abstract class AbstractCacheCommandTest extends \PHPUnit_Framework_TestCase
12+
{
13+
/**
14+
* @var \Magento\Framework\App\Cache\Manager|\PHPUnit_Framework_MockObject_MockObject
15+
*/
16+
protected $cacheManager;
17+
18+
/**
19+
* @var AbstractCacheManageCommand
20+
*/
21+
protected $command;
22+
23+
public function setUp()
24+
{
25+
$this->cacheManager = $this->getMock('Magento\Framework\App\Cache\Manager', [], [], '', false);
26+
}
27+
28+
/**
29+
* Formats expected output for testExecute data providers
30+
*
31+
* @param array $types
32+
* @return string
33+
*/
34+
abstract public function getExpectedExecutionOutput(array $types);
35+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Backend\Test\Unit\Console\Command;
8+
9+
use Symfony\Component\Console\Tester\CommandTester;
10+
11+
abstract class AbstractCacheManageCommandTest extends AbstractCacheCommandTest
12+
{
13+
/**
14+
* @return array
15+
*/
16+
public function testExecuteDataProvider()
17+
{
18+
return [
19+
'implicit all' => [
20+
[],
21+
['A', 'B', 'C'],
22+
$this->getExpectedExecutionOutput(['A', 'B', 'C']),
23+
],
24+
'specified types' => [
25+
['types' => ['A', 'B']],
26+
['A', 'B'],
27+
$this->getExpectedExecutionOutput(['A', 'B']),
28+
],
29+
];
30+
}
31+
32+
/**
33+
* @expectedException \InvalidArgumentException
34+
* @expectedExceptionMessage The following requested cache types are not supported:
35+
*/
36+
public function testExecuteInvalidCacheType()
37+
{
38+
$this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']);
39+
$param = ['types' => ['A', 'D']];
40+
$commandTester = new CommandTester($this->command);
41+
$commandTester->execute($param);
42+
}
43+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Backend\Test\Unit\Console\Command;
8+
9+
abstract class AbstractCacheSetCommandTest extends AbstractCacheManageCommandTest
10+
{
11+
/**
12+
* @return array
13+
*/
14+
public function testExecuteDataProvider()
15+
{
16+
return [
17+
'implicit all' => [
18+
[],
19+
['A', 'B', 'C'],
20+
['A', 'B', 'C'],
21+
$this->getExpectedExecutionOutput(['A', 'B', 'C']),
22+
],
23+
'specified types' => [
24+
['types' => ['A', 'B']],
25+
['A', 'B'],
26+
['A', 'B'],
27+
$this->getExpectedExecutionOutput(['A', 'B']),
28+
],
29+
'no changes' => [
30+
['types' => ['A', 'B']],
31+
['A', 'B'],
32+
[],
33+
$this->getExpectedExecutionOutput([]),
34+
],
35+
];
36+
}
37+
38+
/**
39+
* Formats expected output of cache status change
40+
*
41+
* @param array $changes
42+
* @param bool $enabled
43+
* @return string
44+
*/
45+
public function getExpectedChangeOutput(array $changes, $enabled)
46+
{
47+
if ($changes) {
48+
$output = 'Changed cache status:' . PHP_EOL;
49+
foreach ($changes as $type) {
50+
$output .= sprintf('%30s: %d -> %d', $type, $enabled === false, $enabled === true) . PHP_EOL;
51+
}
52+
} else {
53+
$output = 'There is nothing to change in cache status' . PHP_EOL;
54+
}
55+
return $output;
56+
}
57+
}

app/code/Magento/Backend/Test/Unit/Console/Command/CacheCleanCommandTest.php

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,55 +9,39 @@
99
use Magento\Backend\Console\Command\CacheCleanCommand;
1010
use Symfony\Component\Console\Tester\CommandTester;
1111

12-
class CacheCleanCommandTest extends \PHPUnit_Framework_TestCase
12+
class CacheCleanCommandTest extends AbstractCacheManageCommandTest
1313
{
14-
/**
15-
* @var \Magento\Framework\App\Cache\Manager|\PHPUnit_Framework_MockObject_MockObject
16-
*/
17-
private $cacheManager;
18-
19-
/**
20-
* @var CacheCleanCommand
21-
*/
22-
private $command;
23-
2414
public function setUp()
2515
{
26-
$this->cacheManager = $this->getMock('Magento\Framework\App\Cache\Manager', [], [], '', false);
16+
parent::setUp();
2717
$this->command = new CacheCleanCommand($this->cacheManager);
2818
}
2919

30-
public function testExecute()
31-
{
32-
$this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']);
33-
$this->cacheManager->expects($this->once())->method('clean')->with(['A', 'B']);
34-
$param = ['types' => ['A', 'B']];
35-
$commandTester = new CommandTester($this->command);
36-
$commandTester->execute($param);
37-
$expect = 'Cleaned cache types:' . PHP_EOL . 'A' . PHP_EOL . 'B' . PHP_EOL;
38-
$this->assertEquals($expect, $commandTester->getDisplay());
39-
}
40-
4120
/**
42-
* @expectedException \InvalidArgumentException
43-
* @expectedExceptionMessage The following requested cache types are not supported:
21+
* @param array $param
22+
* @param array $types
23+
* @param string $output
24+
* @dataProvider testExecuteDataProvider
4425
*/
45-
public function testExecuteInvalidCacheType()
26+
public function testExecute($param, $types, $output)
4627
{
4728
$this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']);
48-
$param = ['types' => ['A', 'D']];
29+
$this->cacheManager->expects($this->once())->method('clean')->with($types);
30+
4931
$commandTester = new CommandTester($this->command);
5032
$commandTester->execute($param);
33+
34+
$this->assertEquals($output, $commandTester->getDisplay());
5135
}
5236

53-
public function testExecuteAllCacheType()
37+
/**
38+
* Get expected output based on set of types operated on
39+
*
40+
* @param array $types
41+
* @return string
42+
*/
43+
public function getExpectedExecutionOutput(array $types)
5444
{
55-
$this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']);
56-
$this->cacheManager->expects($this->once())->method('clean')->with(['A', 'B', 'C']);
57-
$param = ['--all' => true];
58-
$commandTester = new CommandTester($this->command);
59-
$commandTester->execute($param);
60-
$expect = 'Cleaned cache types:' . PHP_EOL . 'A' . PHP_EOL . 'B' . PHP_EOL . 'C' . PHP_EOL;
61-
$this->assertEquals($expect, $commandTester->getDisplay());
45+
return 'Cleaned cache types:' . PHP_EOL . implode(PHP_EOL, $types) . PHP_EOL;
6246
}
6347
}

app/code/Magento/Backend/Test/Unit/Console/Command/CacheDisableCommandTest.php

Lines changed: 15 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -9,89 +9,37 @@
99
use Magento\Backend\Console\Command\CacheDisableCommand;
1010
use Symfony\Component\Console\Tester\CommandTester;
1111

12-
class CacheDisableCommandTest extends \PHPUnit_Framework_TestCase
12+
class CacheDisableCommandTest extends AbstractCacheSetCommandTest
1313
{
14-
/**
15-
* @var \Magento\Framework\App\Cache\Manager|\PHPUnit_Framework_MockObject_MockObject
16-
*/
17-
private $cacheManager;
18-
19-
/**
20-
* @var CacheDisableCommand
21-
*/
22-
private $command;
23-
2414
public function setUp()
2515
{
26-
$this->cacheManager = $this->getMock('Magento\Framework\App\Cache\Manager', [], [], '', false);
16+
parent::setUp();
2717
$this->command = new CacheDisableCommand($this->cacheManager);
2818
}
2919

30-
public function testExecute()
31-
{
32-
$this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']);
33-
$this->cacheManager
34-
->expects($this->once())
35-
->method('setEnabled')
36-
->with(['A', 'B'], false)
37-
->willReturn(['A', 'B']);
38-
$param = ['types' => ['A', 'B']];
39-
$commandTester = new CommandTester($this->command);
40-
$commandTester->execute($param);
41-
42-
$expect = 'Changed cache status:' . PHP_EOL;
43-
foreach (['A', 'B'] as $cacheType) {
44-
$expect .= sprintf('%30s: %d -> %d', $cacheType, true, false) . PHP_EOL;
45-
}
46-
47-
$this->assertEquals($expect, $commandTester->getDisplay());
48-
}
49-
50-
public function testExecuteAll()
20+
/**
21+
* @param array $param
22+
* @param array $enable
23+
* @param array $result
24+
* @param string $output
25+
* @dataProvider testExecuteDataProvider
26+
*/
27+
public function testExecute($param, $enable, $result, $output)
5128
{
5229
$this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']);
53-
$this->cacheManager
54-
->expects($this->once())
55-
->method('setEnabled')
56-
->with(['A', 'B', 'C'], false)
57-
->willReturn(['A', 'B', 'C']);
58-
$param = ['--all' => true];
59-
$commandTester = new CommandTester($this->command);
60-
$commandTester->execute($param);
61-
62-
$expect = 'Changed cache status:' . PHP_EOL;
63-
foreach (['A', 'B', 'C'] as $cacheType) {
64-
$expect .= sprintf('%30s: %d -> %d', $cacheType, true, false) . PHP_EOL;
65-
}
66-
$this->assertEquals($expect, $commandTester->getDisplay());
67-
}
30+
$this->cacheManager->expects($this->once())->method('setEnabled')->with($enable, false)->willReturn($result);
6831

69-
public function testExecuteNoChanges()
70-
{
71-
$this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']);
72-
$this->cacheManager
73-
->expects($this->once())
74-
->method('setEnabled')
75-
->with(['A', 'B'], false)
76-
->willReturn([]);
77-
$this->cacheManager->expects($this->never())->method('clean');
78-
$param = ['types' => ['A', 'B']];
7932
$commandTester = new CommandTester($this->command);
8033
$commandTester->execute($param);
8134

82-
$expect = 'There is nothing to change in cache status' . PHP_EOL;
83-
$this->assertEquals($expect, $commandTester->getDisplay());
35+
$this->assertEquals($output, $commandTester->getDisplay());
8436
}
8537

8638
/**
87-
* @expectedException \InvalidArgumentException
88-
* @expectedExceptionMessage The following requested cache types are not supported:
39+
* {@inheritdoc}
8940
*/
90-
public function testExecuteInvalidCacheType()
41+
public function getExpectedExecutionOutput(array $changes)
9142
{
92-
$this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']);
93-
$param = ['types' => ['A', 'D']];
94-
$commandTester = new CommandTester($this->command);
95-
$commandTester->execute($param);
43+
return $this->getExpectedChangeOutput($changes, false);
9644
}
9745
}

0 commit comments

Comments
 (0)