ReadmeCommandTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /*
  3. * This file is part of PHP CS Fixer.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  7. *
  8. * This source file is subject to the MIT license that is bundled
  9. * with this source code in the file LICENSE.
  10. */
  11. namespace PhpCsFixer\Tests\Console\Command;
  12. use PhpCsFixer\Console\Application;
  13. use PHPUnit\Framework\TestCase;
  14. use Symfony\Component\Console\Input\ArrayInput;
  15. use Symfony\Component\Console\Output\BufferedOutput;
  16. use Symfony\Component\Console\Output\OutputInterface;
  17. /**
  18. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  19. *
  20. * @internal
  21. *
  22. * @covers \PhpCsFixer\Console\Command\ReadmeCommand
  23. */
  24. final class ReadmeCommandTest extends TestCase
  25. {
  26. public function testIfReadmeFileIsCorrect()
  27. {
  28. $readmeFile = __DIR__.'/../../../README.rst';
  29. $this->assertFileExists($readmeFile, sprintf('README file "%s" not found.', $readmeFile)); // switch to `assertFileIsReadable` on PHPUnit6
  30. $this->assertIsReadable($readmeFile, sprintf('Cannot read "%s".', $readmeFile));
  31. $this->assertTrue(is_file($readmeFile), sprintf('Expected file "%s" to be a file.', $readmeFile));
  32. $fileContent = file_get_contents($readmeFile);
  33. $this->assertInternalType('string', $fileContent, sprintf('Failed to get content of "%s"', $readmeFile));
  34. $app = new Application();
  35. $input = new ArrayInput(['readme']);
  36. $output = new BufferedOutput();
  37. $output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE);
  38. $output->setDecorated(false);
  39. $exitCode = $app->get('readme')->run($input, $output);
  40. $output = $output->fetch();
  41. // normalize line breaks, these are not important for the tests
  42. $output = str_replace(PHP_EOL, "\n", $output);
  43. $this->assertSame(
  44. 0,
  45. $exitCode,
  46. sprintf("readme command did not exit successfully.\n%s", $output)
  47. );
  48. $this->assertSame(
  49. $output,
  50. $fileContent,
  51. 'README.rst file is not up to date! Do not modify it manually! Regenerate readme with command: `php php-cs-fixer readme > README.rst`.'
  52. );
  53. }
  54. }