PhpUnitTargetVersionTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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\Fixer\PhpUnit;
  13. use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion;
  14. use PhpCsFixer\Tests\TestCase;
  15. /**
  16. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  17. *
  18. * @internal
  19. *
  20. * @covers \PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion
  21. */
  22. final class PhpUnitTargetVersionTest extends TestCase
  23. {
  24. /**
  25. * @dataProvider provideFulfillsCases
  26. *
  27. * @param null|class-string<\Throwable> $exception
  28. */
  29. public function testFulfills(bool $expected, string $candidate, string $target, ?string $exception = null): void
  30. {
  31. if (null !== $exception) {
  32. $this->expectException($exception);
  33. }
  34. self::assertSame(
  35. $expected,
  36. PhpUnitTargetVersion::fulfills($candidate, $target)
  37. );
  38. }
  39. /**
  40. * @return iterable<array{0: bool, 1: string, 2: string, 3?: string}>
  41. */
  42. public static function provideFulfillsCases(): iterable
  43. {
  44. yield [true, PhpUnitTargetVersion::VERSION_NEWEST, PhpUnitTargetVersion::VERSION_5_6];
  45. yield [true, PhpUnitTargetVersion::VERSION_NEWEST, PhpUnitTargetVersion::VERSION_5_2];
  46. yield [true, PhpUnitTargetVersion::VERSION_5_6, PhpUnitTargetVersion::VERSION_5_6];
  47. yield [true, PhpUnitTargetVersion::VERSION_5_6, PhpUnitTargetVersion::VERSION_5_2];
  48. yield [true, PhpUnitTargetVersion::VERSION_5_2, PhpUnitTargetVersion::VERSION_5_2];
  49. yield [false, PhpUnitTargetVersion::VERSION_5_2, PhpUnitTargetVersion::VERSION_5_6];
  50. yield [false, PhpUnitTargetVersion::VERSION_5_2, PhpUnitTargetVersion::VERSION_NEWEST, \LogicException::class];
  51. }
  52. }