ProgressOutputFactoryTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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\Output\Progress;
  13. use PhpCsFixer\Console\Output\OutputContext;
  14. use PhpCsFixer\Console\Output\Progress\DotsOutput;
  15. use PhpCsFixer\Console\Output\Progress\NullOutput;
  16. use PhpCsFixer\Console\Output\Progress\ProgressOutputFactory;
  17. use PhpCsFixer\Console\Output\Progress\ProgressOutputType;
  18. use PhpCsFixer\Tests\TestCase;
  19. use Symfony\Component\Console\Output\NullOutput as SymfonyNullOutput;
  20. /**
  21. * @internal
  22. *
  23. * @covers \PhpCsFixer\Console\Output\Progress\ProgressOutputFactory
  24. */
  25. final class ProgressOutputFactoryTest extends TestCase
  26. {
  27. /**
  28. * @dataProvider provideValidProcessOutputIsCreatedCases
  29. *
  30. * @param class-string<\Throwable> $expectedOutputClass
  31. */
  32. public function testValidProcessOutputIsCreated(
  33. string $outputType,
  34. OutputContext $context,
  35. string $expectedOutputClass
  36. ): void {
  37. self::assertInstanceOf($expectedOutputClass, (new ProgressOutputFactory())->create($outputType, $context));
  38. }
  39. /**
  40. * @return iterable<string, array{string, OutputContext, string}>
  41. */
  42. public static function provideValidProcessOutputIsCreatedCases(): iterable
  43. {
  44. $context = new OutputContext(new SymfonyNullOutput(), 100, 10);
  45. $nullContext = new OutputContext(null, 100, 10);
  46. yield 'none' => [ProgressOutputType::NONE, $context, NullOutput::class];
  47. yield 'dots' => [ProgressOutputType::DOTS, $context, DotsOutput::class];
  48. yield 'dots with null output' => [ProgressOutputType::DOTS, $nullContext, NullOutput::class];
  49. yield 'unsupported type with null output' => ['boom', $nullContext, NullOutput::class];
  50. }
  51. public function testExceptionIsThrownForUnsupportedProcessOutputType(): void
  52. {
  53. $this->expectException(\InvalidArgumentException::class);
  54. (new ProgressOutputFactory())->create(
  55. 'boom',
  56. new OutputContext(new SymfonyNullOutput(), 100, 10)
  57. );
  58. }
  59. }