EncodingFixerTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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\Fixer\Basic;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Fixer\Basic\EncodingFixer
  20. *
  21. * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\Basic\EncodingFixer>
  22. */
  23. final class EncodingFixerTest extends AbstractFixerTestCase
  24. {
  25. /**
  26. * @dataProvider provideFixCases
  27. */
  28. public function testFix(string $expected, ?string $input = null, ?\SplFileInfo $file = null): void
  29. {
  30. $this->doTest($expected, $input, $file);
  31. }
  32. /**
  33. * @return iterable<array{0: string, 1?: string, 2?: \SplFileInfo}>
  34. */
  35. public static function provideFixCases(): iterable
  36. {
  37. yield self::prepareTestCase('test-utf8.case1.php', 'test-utf8.case1-bom.php');
  38. yield self::prepareTestCase('test-utf8.case2.php', 'test-utf8.case2-bom.php');
  39. yield ['<?php '];
  40. }
  41. /**
  42. * @return array{string, null|string, \SplFileInfo}
  43. */
  44. private static function prepareTestCase(string $expectedFilename, ?string $inputFilename = null): array
  45. {
  46. $expectedFile = new \SplFileInfo(__DIR__.'/../../Fixtures/FixerTest/encoding/'.$expectedFilename);
  47. $inputFile = null !== $inputFilename ? new \SplFileInfo(__DIR__.'/../../Fixtures/FixerTest/encoding/'.$inputFilename) : null;
  48. return [
  49. file_get_contents($expectedFile->getRealPath()),
  50. null !== $inputFile ? file_get_contents($inputFile->getRealPath()) : null,
  51. $inputFile ?? $expectedFile,
  52. ];
  53. }
  54. }