SignatureTest.php 3.3 KB

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