CheckCommandTest.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of PHP CS Fixer.
  5. *
  6. * (c) Fabien Potencier <fabien@symfony.com>
  7. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  8. *
  9. * This source file is subject to the MIT license that is bundled
  10. * with this source code in the file LICENSE.
  11. */
  12. namespace PhpCsFixer\Tests\Console\Command;
  13. use PhpCsFixer\Console\Application;
  14. use PhpCsFixer\Console\Command\CheckCommand;
  15. use PhpCsFixer\Tests\TestCase;
  16. use PhpCsFixer\ToolInfo;
  17. use Symfony\Component\Console\Exception\InvalidOptionException;
  18. use Symfony\Component\Console\Tester\CommandTester;
  19. /**
  20. * @internal
  21. *
  22. * @covers \PhpCsFixer\Console\Command\CheckCommand
  23. */
  24. final class CheckCommandTest extends TestCase
  25. {
  26. /**
  27. * This test ensures that `--dry-run` option is not available in `check` command,
  28. * because this command is a proxy for `fix` command which always set `--dry-run` during proxying,
  29. * so it does not make sense to provide this option again.
  30. */
  31. public function testDryRunModeIsUnavailable(): void
  32. {
  33. $application = new Application();
  34. $application->add(new CheckCommand(new ToolInfo()));
  35. $command = $application->find('check');
  36. $commandTester = new CommandTester($command);
  37. $this->expectException(InvalidOptionException::class);
  38. $this->expectExceptionMessageMatches('/--dry-run/');
  39. $commandTester->execute(
  40. [
  41. 'command' => $command->getName(),
  42. '--dry-run' => true,
  43. ]
  44. );
  45. }
  46. }