FileSpecificCodeSampleTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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\FileSpecificCodeSample;
  14. use PhpCsFixer\Tests\TestCase;
  15. /**
  16. * @author Andreas Möller <am@localheinz.com>
  17. *
  18. * @internal
  19. *
  20. * @covers \PhpCsFixer\FixerDefinition\FileSpecificCodeSample
  21. */
  22. final class FileSpecificCodeSampleTest extends TestCase
  23. {
  24. public function testImplementsFileSpecificCodeSampleInterface(): void
  25. {
  26. $sample = new FileSpecificCodeSample(file_get_contents(__FILE__), new \SplFileInfo(__FILE__));
  27. self::assertInstanceOf(\PhpCsFixer\FixerDefinition\FileSpecificCodeSampleInterface::class, $sample);
  28. }
  29. public function testDefaults(): void
  30. {
  31. $code = file_get_contents(__FILE__);
  32. $splFileInfo = new \SplFileInfo(__FILE__);
  33. $sample = new FileSpecificCodeSample(
  34. $code,
  35. $splFileInfo
  36. );
  37. self::assertSame($code, $sample->getCode());
  38. self::assertSame($splFileInfo, $sample->getSplFileInfo());
  39. self::assertNull($sample->getConfiguration());
  40. }
  41. public function testConstructorSetsValues(): void
  42. {
  43. $code = file_get_contents(__FILE__);
  44. $splFileInfo = new \SplFileInfo(__FILE__);
  45. $configuration = [
  46. 'foo' => 'bar',
  47. 'bar' => 'baz',
  48. ];
  49. $sample = new FileSpecificCodeSample(
  50. $code,
  51. $splFileInfo,
  52. $configuration
  53. );
  54. self::assertSame($code, $sample->getCode());
  55. self::assertSame($splFileInfo, $sample->getSplFileInfo());
  56. self::assertSame($configuration, $sample->getConfiguration());
  57. }
  58. }