ProgressOutputFactoryTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. // @phpstan-ignore-next-line argument.type as we explicitly test non-valid $outputType
  38. self::assertInstanceOf($expectedOutputClass, (new ProgressOutputFactory())->create($outputType, $context));
  39. }
  40. /**
  41. * @return iterable<string, array{string, OutputContext, string}>
  42. */
  43. public static function provideValidProcessOutputIsCreatedCases(): iterable
  44. {
  45. $context = new OutputContext(new SymfonyNullOutput(), 100, 10);
  46. $nullContext = new OutputContext(null, 100, 10);
  47. yield 'none' => [ProgressOutputType::NONE, $context, NullOutput::class];
  48. yield 'dots' => [ProgressOutputType::DOTS, $context, DotsOutput::class];
  49. yield 'dots with null output' => [ProgressOutputType::DOTS, $nullContext, NullOutput::class];
  50. yield 'unsupported type with null output' => ['boom', $nullContext, NullOutput::class];
  51. }
  52. public function testExceptionIsThrownForUnsupportedProcessOutputType(): void
  53. {
  54. $this->expectException(\InvalidArgumentException::class);
  55. $outputContext = new OutputContext(new SymfonyNullOutput(), 100, 10);
  56. // @phpstan-ignore-next-line argument.type as we explicitly test non-valid $outputType
  57. (new ProgressOutputFactory())->create('boom', $outputContext);
  58. }
  59. }