FixCommandExitStatusCalculatorTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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\Command\FixCommandExitStatusCalculator;
  14. use PhpCsFixer\Tests\TestCase;
  15. /**
  16. * @author Andreas Möller <am@localheinz.com>
  17. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  18. *
  19. * @internal
  20. *
  21. * @covers \PhpCsFixer\Console\Command\FixCommandExitStatusCalculator
  22. */
  23. final class FixCommandExitStatusCalculatorTest extends TestCase
  24. {
  25. /**
  26. * @dataProvider provideCalculateCases
  27. */
  28. public function testCalculate(
  29. int $expected,
  30. bool $isDryRun,
  31. bool $hasChangedFiles,
  32. bool $hasInvalidErrors,
  33. bool $hasExceptionErrors,
  34. bool $hasLintErrorsAfterFixing
  35. ): void {
  36. $calculator = new FixCommandExitStatusCalculator();
  37. self::assertSame(
  38. $expected,
  39. $calculator->calculate(
  40. $isDryRun,
  41. $hasChangedFiles,
  42. $hasInvalidErrors,
  43. $hasExceptionErrors,
  44. $hasLintErrorsAfterFixing
  45. )
  46. );
  47. }
  48. /**
  49. * @return iterable<array{int, bool, bool, bool, bool, bool}>
  50. */
  51. public static function provideCalculateCases(): iterable
  52. {
  53. yield [0, true, false, false, false, false];
  54. yield [0, false, false, false, false, false];
  55. yield [8, true, true, false, false, false];
  56. yield [0, false, true, false, false, false];
  57. yield [4, true, false, true, false, false];
  58. yield [0, false, false, true, false, false];
  59. yield [12, true, true, true, false, false];
  60. yield [0, false, true, true, false, false];
  61. yield [76, true, true, true, true, false];
  62. yield [64, false, false, false, false, true];
  63. yield [64, false, false, false, true, false];
  64. yield [64, false, false, false, true, true];
  65. yield [8 | 64, true, true, false, true, true];
  66. }
  67. }