Skip to content

Commit c75c203

Browse files
author
Dale Sikkema
committed
Merge branch 'MAGETWO-43787-clear-varnish-cli' into MAGETWO-44154-cg-race-condition
2 parents be0ff6b + 74c6413 commit c75c203

File tree

12 files changed

+68
-20
lines changed

12 files changed

+68
-20
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,28 @@
66

77
namespace Magento\Backend\Console\Command;
88

9+
use Magento\Framework\Event\ManagerInterface as EventManagerInterface;
910
use Symfony\Component\Console\Input\InputInterface;
1011
use Symfony\Component\Console\Output\OutputInterface;
12+
use Magento\Framework\App\Cache\Manager;
1113

1214
abstract class AbstractCacheTypeManageCommand extends AbstractCacheManageCommand
1315
{
16+
/** @var EventManagerInterface */
17+
protected $eventManager;
18+
19+
/**
20+
* @param Manager $cacheManager
21+
* @param EventManagerInterface $eventManager
22+
*/
23+
public function __construct(
24+
Manager $cacheManager,
25+
EventManagerInterface $eventManager
26+
) {
27+
$this->eventManager = $eventManager;
28+
parent::__construct($cacheManager);
29+
}
30+
1431
/**
1532
* Perform a cache management action on cache types
1633
*

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ protected function configure()
2929
*/
3030
protected function performAction(array $cacheTypes)
3131
{
32+
$this->eventManager->dispatch('adminhtml_cache_flush_system');
3233
$this->cacheManager->clean($cacheTypes);
3334
}
3435

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ protected function configure()
2929
*/
3030
protected function performAction(array $cacheTypes)
3131
{
32+
$this->eventManager->dispatch('adminhtml_cache_flush_all');
3233
$this->cacheManager->flush($cacheTypes);
3334
}
3435

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ abstract class AbstractCacheCommandTest extends \PHPUnit_Framework_TestCase
1313
/**
1414
* @var \Magento\Framework\App\Cache\Manager|\PHPUnit_Framework_MockObject_MockObject
1515
*/
16-
protected $cacheManager;
16+
protected $cacheManagerMock;
1717

1818
/**
1919
* @var AbstractCacheManageCommand
@@ -22,7 +22,7 @@ abstract class AbstractCacheCommandTest extends \PHPUnit_Framework_TestCase
2222

2323
public function setUp()
2424
{
25-
$this->cacheManager = $this->getMock('Magento\Framework\App\Cache\Manager', [], [], '', false);
25+
$this->cacheManagerMock = $this->getMock('Magento\Framework\App\Cache\Manager', [], [], '', false);
2626
}
2727

2828
/**

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@
1010

1111
abstract class AbstractCacheManageCommandTest extends AbstractCacheCommandTest
1212
{
13+
/** @var string */
14+
protected $cacheEventName;
15+
16+
/** @var \Magento\Framework\Event\ManagerInterface | \PHPUnit_Framework_MockObject_MockObject */
17+
protected $eventManagerMock;
18+
19+
public function setUp()
20+
{
21+
$this->eventManagerMock = $this->getMockBuilder('\Magento\Framework\Event\ManagerInterface')
22+
->disableOriginalConstructor()
23+
->getMock();
24+
parent::setUp();
25+
}
26+
1327
/**
1428
* @return array
1529
*/
@@ -35,7 +49,7 @@ public function testExecuteDataProvider()
3549
*/
3650
public function testExecuteInvalidCacheType()
3751
{
38-
$this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']);
52+
$this->cacheManagerMock->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']);
3953
$param = ['types' => ['A', 'D']];
4054
$commandTester = new CommandTester($this->command);
4155
$commandTester->execute($param);

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ class CacheCleanCommandTest extends AbstractCacheManageCommandTest
1313
{
1414
public function setUp()
1515
{
16+
$this->cacheEventName = 'adminhtml_cache_flush_system';
1617
parent::setUp();
17-
$this->command = new CacheCleanCommand($this->cacheManager);
18+
$this->command = new CacheCleanCommand($this->cacheManagerMock, $this->eventManagerMock);
1819
}
1920

2021
/**
@@ -25,8 +26,9 @@ public function setUp()
2526
*/
2627
public function testExecute($param, $types, $output)
2728
{
28-
$this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']);
29-
$this->cacheManager->expects($this->once())->method('clean')->with($types);
29+
$this->cacheManagerMock->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']);
30+
$this->cacheManagerMock->expects($this->once())->method('clean')->with($types);
31+
$this->eventManagerMock->expects($this->once())->method('dispatch')->with($this->cacheEventName);
3032

3133
$commandTester = new CommandTester($this->command);
3234
$commandTester->execute($param);

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class CacheDisableCommandTest extends AbstractCacheSetCommandTest
1414
public function setUp()
1515
{
1616
parent::setUp();
17-
$this->command = new CacheDisableCommand($this->cacheManager);
17+
$this->command = new CacheDisableCommand($this->cacheManagerMock);
1818
}
1919

2020
/**
@@ -26,8 +26,13 @@ public function setUp()
2626
*/
2727
public function testExecute($param, $enable, $result, $output)
2828
{
29-
$this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']);
30-
$this->cacheManager->expects($this->once())->method('setEnabled')->with($enable, false)->willReturn($result);
29+
$this->cacheManagerMock->expects($this->once())
30+
->method('getAvailableTypes')
31+
->willReturn(['A', 'B', 'C']);
32+
$this->cacheManagerMock->expects($this->once())
33+
->method('setEnabled')
34+
->with($enable, false)
35+
->willReturn($result);
3136

3237
$commandTester = new CommandTester($this->command);
3338
$commandTester->execute($param);

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class CacheEnableCommandTest extends AbstractCacheSetCommandTest
1414
public function setUp()
1515
{
1616
parent::setUp();
17-
$this->command = new CacheEnableCommand($this->cacheManager);
17+
$this->command = new CacheEnableCommand($this->cacheManagerMock);
1818
}
1919

2020
/**
@@ -26,9 +26,15 @@ public function setUp()
2626
*/
2727
public function testExecute($param, $enable, $result, $output)
2828
{
29-
$this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']);
30-
$this->cacheManager->expects($this->once())->method('setEnabled')->with($enable, true)->willReturn($result);
31-
$this->cacheManager->expects($result === [] ? $this->never() : $this->once())->method('clean')->with($enable);
29+
$this->cacheManagerMock->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']);
30+
$this->cacheManagerMock->expects($this->once())
31+
->method('setEnabled')
32+
->with($enable, true)
33+
->willReturn($result);
34+
$cleanInvocationCount = $result === [] ? 0 : 1;
35+
$this->cacheManagerMock->expects($this->exactly($cleanInvocationCount))
36+
->method('clean')
37+
->with($enable);
3238

3339
$commandTester = new CommandTester($this->command);
3440
$commandTester->execute($param);

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ class CacheFlushCommandTest extends AbstractCacheManageCommandTest
1313
{
1414
public function setUp()
1515
{
16+
$this->cacheEventName = 'adminhtml_cache_flush_all';
1617
parent::setUp();
17-
$this->command = new CacheFlushCommand($this->cacheManager);
18+
$this->command = new CacheFlushCommand($this->cacheManagerMock, $this->eventManagerMock);
1819
}
1920

2021
/**
@@ -25,8 +26,9 @@ public function setUp()
2526
*/
2627
public function testExecute($param, $types, $output)
2728
{
28-
$this->cacheManager->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']);
29-
$this->cacheManager->expects($this->once())->method('flush')->with($types);
29+
$this->cacheManagerMock->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']);
30+
$this->cacheManagerMock->expects($this->once())->method('flush')->with($types);
31+
$this->eventManagerMock->expects($this->once())->method('dispatch')->with($this->cacheEventName);
3032

3133
$commandTester = new CommandTester($this->command);
3234
$commandTester->execute($param);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ class CacheStatusCommandTest extends AbstractCacheCommandTest
1414
public function setUp()
1515
{
1616
parent::setUp();
17-
$this->command = new CacheStatusCommand($this->cacheManager);
17+
$this->command = new CacheStatusCommand($this->cacheManagerMock);
1818
}
1919

2020
public function testExecute()
2121
{
2222
$cacheTypes = ['A' => 0, 'B' => 1, 'C' => 1];
23-
$this->cacheManager->expects($this->once())->method('getStatus')->willReturn($cacheTypes);
23+
$this->cacheManagerMock->expects($this->once())->method('getStatus')->willReturn($cacheTypes);
2424
$commandTester = new CommandTester($this->command);
2525
$commandTester->execute([]);
2626

0 commit comments

Comments
 (0)