VersionSpecificCodeSampleTest.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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\FixerDefinition;
  12. use PhpCsFixer\FixerDefinition\VersionSpecificationInterface;
  13. use PhpCsFixer\FixerDefinition\VersionSpecificCodeSample;
  14. use PhpCsFixer\Tests\TestCase;
  15. use Prophecy\Prophecy;
  16. /**
  17. * @author Andreas Möller <am@localheinz.com>
  18. *
  19. * @internal
  20. *
  21. * @covers \PhpCsFixer\FixerDefinition\VersionSpecificCodeSample
  22. */
  23. final class VersionSpecificCodeSampleTest extends TestCase
  24. {
  25. public function testConstructorSetsValues()
  26. {
  27. $code = '<php echo $foo;';
  28. $configuration = [
  29. 'foo' => 'bar',
  30. ];
  31. $codeSample = new VersionSpecificCodeSample(
  32. $code,
  33. $this->createVersionSpecificationMock()->reveal(),
  34. $configuration
  35. );
  36. $this->assertSame($code, $codeSample->getCode());
  37. $this->assertSame($configuration, $codeSample->getConfiguration());
  38. }
  39. public function testConfigurationDefaultsToNull()
  40. {
  41. $codeSample = new VersionSpecificCodeSample(
  42. '<php echo $foo;',
  43. $this->createVersionSpecificationMock()->reveal()
  44. );
  45. $this->assertNull($codeSample->getConfiguration());
  46. }
  47. /**
  48. * @dataProvider provideIsSuitableForVersionUsesVersionSpecificationCases
  49. *
  50. * @param int $version
  51. * @param bool $isSatisfied
  52. */
  53. public function testIsSuitableForUsesVersionSpecification($version, $isSatisfied)
  54. {
  55. $versionSpecification = $this->createVersionSpecificationMock();
  56. $versionSpecification
  57. ->isSatisfiedBy($version)
  58. ->willReturn($isSatisfied);
  59. $codeSample = new VersionSpecificCodeSample(
  60. '<php echo $foo;',
  61. $versionSpecification->reveal()
  62. );
  63. $this->assertSame($isSatisfied, $codeSample->isSuitableFor($version));
  64. }
  65. /**
  66. * @return array
  67. */
  68. public function provideIsSuitableForVersionUsesVersionSpecificationCases()
  69. {
  70. return [
  71. 'is-satisfied' => [PHP_VERSION_ID, true],
  72. 'is-not-satisfied' => [PHP_VERSION_ID, false],
  73. ];
  74. }
  75. /**
  76. * @return Prophecy\ObjectProphecy|VersionSpecificationInterface
  77. */
  78. private function createVersionSpecificationMock()
  79. {
  80. return $this->prophesize(\PhpCsFixer\FixerDefinition\VersionSpecificationInterface::class);
  81. }
  82. }