VersionSpecificationTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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\FixerDefinition;
  13. use PhpCsFixer\FixerDefinition\VersionSpecification;
  14. use PhpCsFixer\Tests\TestCase;
  15. /**
  16. * @author Andreas Möller <am@localheinz.com>
  17. *
  18. * @internal
  19. *
  20. * @covers \PhpCsFixer\FixerDefinition\VersionSpecification
  21. */
  22. final class VersionSpecificationTest extends TestCase
  23. {
  24. public function testConstructorRequiresEitherMinimumOrMaximum(): void
  25. {
  26. $this->expectException(\InvalidArgumentException::class);
  27. new VersionSpecification();
  28. }
  29. /**
  30. * @dataProvider provideConstructorRejectsInvalidValuesCases
  31. */
  32. public function testConstructorRejectsInvalidValues(?int $minimum = null, ?int $maximum = null): void
  33. {
  34. $this->expectException(\InvalidArgumentException::class);
  35. new VersionSpecification(
  36. $minimum,
  37. $maximum
  38. );
  39. }
  40. /**
  41. * @return iterable<string, array{null|int, null|int}>
  42. */
  43. public static function provideConstructorRejectsInvalidValuesCases(): iterable
  44. {
  45. yield 'minimum is negative' => [-1, null];
  46. yield 'minimum is zero ' => [0, null];
  47. yield 'maximum is negative' => [null, -1];
  48. yield 'maximum is zero ' => [null, 0];
  49. yield 'maximum less than minimum' => [32, 31];
  50. }
  51. /**
  52. * @dataProvider provideIsSatisfiedByReturnsTrueCases
  53. */
  54. public function testIsSatisfiedByReturnsTrue(?int $minimum, ?int $maximum, int $actual): void
  55. {
  56. $versionSpecification = new VersionSpecification(
  57. $minimum,
  58. $maximum
  59. );
  60. self::assertTrue($versionSpecification->isSatisfiedBy($actual));
  61. }
  62. /**
  63. * @return iterable<string, array{null|int, null|int, int}>
  64. */
  65. public static function provideIsSatisfiedByReturnsTrueCases(): iterable
  66. {
  67. yield 'version-same-as-maximum' => [null, 100, 100];
  68. yield 'version-same-as-minimum' => [200, null, 200];
  69. yield 'version-between-minimum-and-maximum' => [299, 301, 300];
  70. yield 'version-same-as-minimum-and-maximum' => [400, 400, 400];
  71. }
  72. /**
  73. * @dataProvider provideIsSatisfiedByReturnsFalseCases
  74. */
  75. public function testIsSatisfiedByReturnsFalse(?int $minimum, ?int $maximum, int $actual): void
  76. {
  77. $versionSpecification = new VersionSpecification(
  78. $minimum,
  79. $maximum
  80. );
  81. self::assertFalse($versionSpecification->isSatisfiedBy($actual));
  82. }
  83. /**
  84. * @return iterable<string, array{null|int, null|int, int}>
  85. */
  86. public static function provideIsSatisfiedByReturnsFalseCases(): iterable
  87. {
  88. yield 'version-greater-than-maximum' => [null, 1_000, 1_001];
  89. yield 'version-less-than-minimum' => [2_000, null, 1_999];
  90. }
  91. }