SetModeCommandTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Deploy\Test\Unit\Console\Command;
  7. use Magento\Deploy\Console\Command\SetModeCommand;
  8. use Symfony\Component\Console\Tester\CommandTester;
  9. /**
  10. * @package Magento\Deploy\Test\Unit\Console\Command
  11. */
  12. class SetModeCommandTest extends \PHPUnit\Framework\TestCase
  13. {
  14. /**
  15. * @var \Magento\Deploy\Model\Mode|\PHPUnit_Framework_MockObject_MockObject
  16. */
  17. private $modeMock;
  18. /**
  19. * @var SetModeCommand
  20. */
  21. private $command;
  22. /**
  23. * @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
  24. */
  25. private $objectManagerMock;
  26. protected function setUp()
  27. {
  28. $this->objectManagerMock = $this->getMockForAbstractClass(\Magento\Framework\ObjectManagerInterface::class);
  29. $this->modeMock = $this->createMock(\Magento\Deploy\Model\Mode::class);
  30. $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  31. $this->command = $objectManager->getObject(
  32. \Magento\Deploy\Console\Command\SetModeCommand::class,
  33. ['objectManager' => $this->objectManagerMock]
  34. );
  35. $this->objectManagerMock->expects($this->once())->method('create')->willReturn($this->modeMock);
  36. }
  37. public function testSetProductionMode()
  38. {
  39. $this->modeMock->expects($this->once())->method('enableProductionMode');
  40. $tester = new CommandTester($this->command);
  41. $tester->execute(['mode' => 'production']);
  42. $this->assertContains(
  43. "production mode",
  44. $tester->getDisplay()
  45. );
  46. }
  47. public function testSetDeveloperMode()
  48. {
  49. $this->modeMock->expects($this->once())->method('enableDeveloperMode');
  50. $tester = new CommandTester($this->command);
  51. $tester->execute(['mode' => 'developer']);
  52. $this->assertContains(
  53. "developer mode",
  54. $tester->getDisplay()
  55. );
  56. }
  57. public function testSetDefaultMode()
  58. {
  59. $this->modeMock->expects($this->once())->method('enableDefaultMode');
  60. $tester = new CommandTester($this->command);
  61. $tester->execute(['mode' => 'default']);
  62. $this->assertContains(
  63. "default mode",
  64. $tester->getDisplay()
  65. );
  66. }
  67. public function testSetProductionSkipCompilation()
  68. {
  69. $this->modeMock->expects($this->once())->method('enableProductionModeMinimal');
  70. $tester = new CommandTester($this->command);
  71. $tester->execute(['mode' => 'production', '--skip-compilation' => true]);
  72. $this->assertContains(
  73. "production mode",
  74. $tester->getDisplay()
  75. );
  76. }
  77. public function testSetInvalidMode()
  78. {
  79. $tester = new CommandTester($this->command);
  80. $tester->execute(['mode' => 'invalid-mode']);
  81. $this->assertContains(
  82. 'The mode can\'t be switched to "invalid-mode".',
  83. $tester->getDisplay()
  84. );
  85. }
  86. }