CacheEnableCommandTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Backend\Test\Unit\Console\Command;
  7. use Magento\Backend\Console\Command\CacheEnableCommand;
  8. use Symfony\Component\Console\Tester\CommandTester;
  9. class CacheEnableCommandTest extends AbstractCacheSetCommandTest
  10. {
  11. protected function setUp()
  12. {
  13. parent::setUp();
  14. $this->command = new CacheEnableCommand($this->cacheManagerMock);
  15. }
  16. /**
  17. * @param array $param
  18. * @param array $enable
  19. * @param array $result
  20. * @param string $output
  21. * @dataProvider executeDataProvider
  22. */
  23. public function testExecute($param, $enable, $result, $output)
  24. {
  25. $this->cacheManagerMock->expects($this->once())->method('getAvailableTypes')->willReturn(['A', 'B', 'C']);
  26. $this->cacheManagerMock->expects($this->once())
  27. ->method('setEnabled')
  28. ->with($enable, true)
  29. ->willReturn($result);
  30. $cleanInvocationCount = $result === [] ? 0 : 1;
  31. $this->cacheManagerMock->expects($this->exactly($cleanInvocationCount))
  32. ->method('clean')
  33. ->with($enable);
  34. $commandTester = new CommandTester($this->command);
  35. $commandTester->execute($param);
  36. $this->assertEquals($output, $commandTester->getDisplay());
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function getExpectedExecutionOutput(array $enabled)
  42. {
  43. $output = $this->getExpectedChangeOutput($enabled, true);
  44. if ($enabled) {
  45. $output .= 'Cleaned cache types:' . PHP_EOL;
  46. $output .= implode(PHP_EOL, $enabled) . PHP_EOL;
  47. }
  48. return $output;
  49. }
  50. }