SignatureTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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\Cache;
  13. use PhpCsFixer\Cache\Signature;
  14. use PhpCsFixer\Cache\SignatureInterface;
  15. use PhpCsFixer\Tests\TestCase;
  16. /**
  17. * @author Andreas Möller <am@localheinz.com>
  18. *
  19. * @internal
  20. *
  21. * @covers \PhpCsFixer\Cache\Signature
  22. */
  23. final class SignatureTest extends TestCase
  24. {
  25. public function testIsFinal(): void
  26. {
  27. $reflection = new \ReflectionClass(Signature::class);
  28. self::assertTrue($reflection->isFinal());
  29. }
  30. public function testImplementsSignatureInterface(): void
  31. {
  32. $reflection = new \ReflectionClass(Signature::class);
  33. self::assertTrue($reflection->implementsInterface(SignatureInterface::class));
  34. }
  35. public function testConstructorSetsValues(): void
  36. {
  37. $php = PHP_VERSION;
  38. $version = '3.0';
  39. $indent = ' ';
  40. $lineEnding = PHP_EOL;
  41. $rules = ['foo' => true, 'bar' => false];
  42. $signature = new Signature($php, $version, $indent, $lineEnding, $rules);
  43. self::assertSame($php, $signature->getPhpVersion());
  44. self::assertSame($version, $signature->getFixerVersion());
  45. self::assertSame($indent, $signature->getIndent());
  46. self::assertSame($lineEnding, $signature->getLineEnding());
  47. self::assertSame($rules, $signature->getRules());
  48. }
  49. /**
  50. * @dataProvider provideEqualsReturnsFalseIfValuesAreNotIdenticalCases
  51. */
  52. public function testEqualsReturnsFalseIfValuesAreNotIdentical(Signature $signature, Signature $anotherSignature): void
  53. {
  54. self::assertFalse($signature->equals($anotherSignature));
  55. }
  56. /**
  57. * @return iterable<string, array{Signature, Signature}>
  58. */
  59. public static function provideEqualsReturnsFalseIfValuesAreNotIdenticalCases(): iterable
  60. {
  61. $php = PHP_VERSION;
  62. $version = '2.0';
  63. $indent = ' ';
  64. $lineEnding = "\n";
  65. $rules = ['foo' => true, 'bar' => false];
  66. $base = new Signature($php, $version, $indent, $lineEnding, $rules);
  67. yield 'php' => [
  68. $base,
  69. new Signature('50400', $version, $indent, $lineEnding, $rules),
  70. ];
  71. yield 'version' => [
  72. $base,
  73. new Signature($php, '2.12', $indent, $lineEnding, $rules),
  74. ];
  75. yield 'indent' => [
  76. $base,
  77. new Signature($php, $version, "\t", $lineEnding, $rules),
  78. ];
  79. yield 'lineEnding' => [
  80. $base,
  81. new Signature($php, $version, $indent, "\r\n", $rules),
  82. ];
  83. yield 'rules' => [
  84. $base,
  85. new Signature($php, $version, $indent, $lineEnding, ['foo' => false]),
  86. ];
  87. }
  88. public function testEqualsReturnsTrueIfValuesAreIdentical(): void
  89. {
  90. $php = PHP_VERSION;
  91. $version = '2.0';
  92. $indent = ' ';
  93. $lineEnding = PHP_EOL;
  94. $rules = ['foo' => true, 'bar' => false];
  95. $signature = new Signature($php, $version, $indent, $lineEnding, $rules);
  96. $anotherSignature = new Signature($php, $version, $indent, $lineEnding, $rules);
  97. self::assertTrue($signature->equals($anotherSignature));
  98. }
  99. }