SignatureTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /*
  3. * This file is part of PHP CS Fixer.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  7. *
  8. * This source file is subject to the MIT license that is bundled
  9. * with this source code in the file LICENSE.
  10. */
  11. namespace PhpCsFixer\Tests\Cache;
  12. use PhpCsFixer\Cache\Signature;
  13. use PhpCsFixer\Tests\TestCase;
  14. /**
  15. * @author Andreas Möller <am@localheinz.com>
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Cache\Signature
  20. */
  21. final class SignatureTest extends TestCase
  22. {
  23. public function testIsFinal()
  24. {
  25. $reflection = new \ReflectionClass(\PhpCsFixer\Cache\Signature::class);
  26. static::assertTrue($reflection->isFinal());
  27. }
  28. public function testImplementsSignatureInterface()
  29. {
  30. $reflection = new \ReflectionClass(\PhpCsFixer\Cache\Signature::class);
  31. static::assertTrue($reflection->implementsInterface(\PhpCsFixer\Cache\SignatureInterface::class));
  32. }
  33. public function testConstructorSetsValues()
  34. {
  35. $php = PHP_VERSION;
  36. $version = '2.0';
  37. $indent = ' ';
  38. $lineEnding = PHP_EOL;
  39. $rules = [
  40. 'foo',
  41. 'bar',
  42. ];
  43. $signature = new Signature(
  44. $php,
  45. $version,
  46. $indent,
  47. $lineEnding,
  48. $rules
  49. );
  50. static::assertSame($php, $signature->getPhpVersion());
  51. static::assertSame($version, $signature->getFixerVersion());
  52. static::assertSame($indent, $signature->getIndent());
  53. static::assertSame($lineEnding, $signature->getLineEnding());
  54. static::assertSame($rules, $signature->getRules());
  55. }
  56. /**
  57. * @dataProvider provideEqualsReturnsFalseIfValuesAreNotIdenticalCases
  58. *
  59. * @param Signature $signature
  60. * @param Signature $anotherSignature
  61. */
  62. public function testEqualsReturnsFalseIfValuesAreNotIdentical($signature, $anotherSignature)
  63. {
  64. static::assertFalse($signature->equals($anotherSignature));
  65. }
  66. public function provideEqualsReturnsFalseIfValuesAreNotIdenticalCases()
  67. {
  68. $php = PHP_VERSION;
  69. $version = '2.0';
  70. $indent = ' ';
  71. $lineEnding = "\n";
  72. $rules = [
  73. 'foo',
  74. 'bar',
  75. ];
  76. $base = new Signature($php, $version, $indent, $lineEnding, $rules);
  77. yield 'php' => [
  78. $base,
  79. new Signature('50400', $version, $indent, $lineEnding, $rules),
  80. ];
  81. yield 'version' => [
  82. $base,
  83. new Signature($php, '2.12', $indent, $lineEnding, $rules),
  84. ];
  85. yield 'indent' => [
  86. $base,
  87. new Signature($php, $version, "\t", $lineEnding, $rules),
  88. ];
  89. yield 'lineEnding' => [
  90. $base,
  91. new Signature($php, $version, $indent, "\r\n", $rules),
  92. ];
  93. yield 'rules' => [
  94. $base,
  95. new Signature($php, $version, $indent, $lineEnding, ['foo']),
  96. ];
  97. }
  98. public function testEqualsReturnsTrueIfValuesAreIdentical()
  99. {
  100. $php = PHP_VERSION;
  101. $version = '2.0';
  102. $indent = ' ';
  103. $lineEnding = PHP_EOL;
  104. $rules = [
  105. 'foo',
  106. 'bar',
  107. ];
  108. $signature = new Signature(
  109. $php,
  110. $version,
  111. $indent,
  112. $lineEnding,
  113. $rules
  114. );
  115. $anotherSignature = new Signature(
  116. $php,
  117. $version,
  118. $indent,
  119. $lineEnding,
  120. $rules
  121. );
  122. static::assertTrue($signature->equals($anotherSignature));
  123. }
  124. }