ApplicationTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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;
  13. use PhpCsFixer\Console\Application;
  14. use PhpCsFixer\Console\Command\WorkerCommand;
  15. use PhpCsFixer\Tests\TestCase;
  16. use PhpCsFixer\ToolInfo;
  17. use Symfony\Component\Console\Tester\ApplicationTester;
  18. /**
  19. * @internal
  20. *
  21. * @covers \PhpCsFixer\Console\Application
  22. */
  23. final class ApplicationTest extends TestCase
  24. {
  25. public function testApplication(): void
  26. {
  27. $regex = '/^PHP CS Fixer <info>\d+.\d+.\d+(-DEV)?<\/info> <info>.+<\/info>'
  28. .' by <comment>Fabien Potencier<\/comment>, <comment>Dariusz Ruminski<\/comment> and <comment>contributors<\/comment>\.'
  29. ."\nPHP runtime: <info>\\d+.\\d+.\\d+(-dev)?<\\/info>$/";
  30. self::assertMatchesRegularExpression($regex, (new Application())->getLongVersion());
  31. }
  32. public function testGetMajorVersion(): void
  33. {
  34. self::assertSame(3, Application::getMajorVersion());
  35. }
  36. public function testWorkerExceptionsAreRenderedInMachineFriendlyWay(): void
  37. {
  38. $app = new Application();
  39. $app->add(new WorkerCommand(new ToolInfo()));
  40. $app->setAutoExit(false); // see: https://symfony.com/doc/current/console.html#testing-commands
  41. $appTester = new ApplicationTester($app);
  42. $appTester->run(['worker']);
  43. self::assertStringContainsString(
  44. WorkerCommand::ERROR_PREFIX.'{"class":"PhpCsFixer\\\Runner\\\Parallel\\\ParallelisationException","message":"Missing parallelisation options"',
  45. $appTester->getDisplay()
  46. );
  47. }
  48. }