ProfilerDisableCommandTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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\ProfilerDisableCommand;
  8. use Magento\Framework\Filesystem\Io\File;
  9. use PHPUnit\Framework\TestCase;
  10. use Symfony\Component\Console\Tester\CommandTester;
  11. /**
  12. * Class ProfilerDisableCommandTest
  13. *
  14. * Tests dev:profiler:disable command.
  15. */
  16. class ProfilerDisableCommandTest extends TestCase
  17. {
  18. /**
  19. * @var File|\PHPUnit_Framework_MockObject_MockObject
  20. */
  21. private $filesystemMock;
  22. /**
  23. * Test disabling the profiler by command.
  24. *
  25. * @param bool $fileExists
  26. * @param string $expectedOutput
  27. * @dataProvider commandDataProvider
  28. */
  29. public function testCommand(bool $fileExists, string $expectedOutput)
  30. {
  31. $this->filesystemMock
  32. ->expects($this->once())
  33. ->method('rm')
  34. ->with(BP . '/' . ProfilerDisableCommand::PROFILER_FLAG_FILE);
  35. $this->filesystemMock
  36. ->expects($this->once())
  37. ->method('fileExists')
  38. ->with(BP . '/' . ProfilerDisableCommand::PROFILER_FLAG_FILE)
  39. ->willReturn($fileExists);
  40. /** @var ProfilerDisableCommand $command */
  41. $command = new ProfilerDisableCommand($this->filesystemMock);
  42. $commandTester = new CommandTester($command);
  43. $commandTester->execute([]);
  44. self::assertEquals(
  45. $expectedOutput,
  46. trim(str_replace(PHP_EOL, ' ', $commandTester->getDisplay()))
  47. );
  48. }
  49. /**
  50. * Data provider for testCommand.
  51. *
  52. * @return array
  53. */
  54. public function commandDataProvider()
  55. {
  56. return [
  57. [true, 'Something went wrong while disabling the profiler.'],
  58. [false, 'Profiler disabled.'],
  59. ];
  60. }
  61. /**
  62. * @inheritdoc
  63. */
  64. protected function setUp()
  65. {
  66. $this->filesystemMock = $this->getMockBuilder(File::class)
  67. ->disableOriginalConstructor()
  68. ->getMock();
  69. }
  70. }