ProfilerEnableCommandTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Developer\Test\Unit\Console\Command;
  7. use Magento\Developer\Console\Command\ProfilerEnableCommand;
  8. use Magento\Framework\Filesystem\Io\File;
  9. use PHPUnit\Framework\TestCase;
  10. use Symfony\Component\Console\Tester\CommandTester;
  11. /**
  12. * Class ProfilerEnableCommandTest
  13. *
  14. * Tests dev:profiler:enable command.
  15. */
  16. class ProfilerEnableCommandTest extends TestCase
  17. {
  18. /**
  19. * @var File|\PHPUnit_Framework_MockObject_MockObject
  20. */
  21. private $filesystemMock;
  22. /**
  23. * Tests enabling the profiler by command.
  24. *
  25. * @param string $inputType
  26. * @param bool $fileExists
  27. * @param string $expectedOutput
  28. * @dataProvider commandDataProvider
  29. */
  30. public function testCommand(string $inputType, bool $fileExists, string $expectedOutput)
  31. {
  32. $this->filesystemMock
  33. ->expects($this->once())
  34. ->method('write')
  35. ->with(
  36. BP . '/' . ProfilerEnableCommand::PROFILER_FLAG_FILE,
  37. $inputType ?: ProfilerEnableCommand::TYPE_DEFAULT
  38. );
  39. $this->filesystemMock
  40. ->expects($this->once())
  41. ->method('fileExists')
  42. ->with(BP . '/' . ProfilerEnableCommand::PROFILER_FLAG_FILE)
  43. ->willReturn($fileExists);
  44. /** @var ProfilerEnableCommand $command */
  45. $command = new ProfilerEnableCommand($this->filesystemMock);
  46. $commandTester = new CommandTester($command);
  47. $commandTester->execute(['type' => $inputType]);
  48. self::assertEquals(
  49. $expectedOutput,
  50. trim(str_replace(PHP_EOL, ' ', $commandTester->getDisplay()))
  51. );
  52. }
  53. /**
  54. * Data provider for testCommand.
  55. *
  56. * @return array
  57. */
  58. public function commandDataProvider()
  59. {
  60. return [
  61. [
  62. '',
  63. true,
  64. 'Profiler enabled with html output.'
  65. ],
  66. [
  67. '',
  68. false,
  69. 'Something went wrong while enabling the profiler.'
  70. ],
  71. [
  72. 'html',
  73. true,
  74. 'Profiler enabled with html output.'
  75. ],
  76. [
  77. 'html',
  78. false,
  79. 'Something went wrong while enabling the profiler.'
  80. ],
  81. [
  82. 'csvfile',
  83. true,
  84. 'Profiler enabled with csvfile output. Output will be saved in /var/log/profiler.csv'
  85. ],
  86. [
  87. 'csvfile',
  88. false,
  89. 'Something went wrong while enabling the profiler.'
  90. ],
  91. [
  92. 'xml',
  93. true,
  94. 'Type xml is not one of the built-in output types (html, csvfile). ' .
  95. 'Profiler enabled with xml output.'
  96. ],
  97. [
  98. 'xml',
  99. false,
  100. 'Type xml is not one of the built-in output types (html, csvfile). ' .
  101. 'Something went wrong while enabling the profiler.'
  102. ],
  103. ];
  104. }
  105. /**
  106. * @inheritdoc
  107. */
  108. protected function setUp()
  109. {
  110. $this->filesystemMock = $this->getMockBuilder(File::class)
  111. ->disableOriginalConstructor()
  112. ->getMock();
  113. }
  114. }