EncodingFixerTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. final class EncodingFixerTest extends AbstractFixerTestCase
  22. {
  23. /**
  24. * @dataProvider provideFixCases
  25. */
  26. public function testFix(string $expected, ?string $input = null, \SplFileInfo $file = null): void
  27. {
  28. $this->doTest($expected, $input, $file);
  29. }
  30. public static function provideFixCases(): iterable
  31. {
  32. yield self::prepareTestCase('test-utf8.case1.php', 'test-utf8.case1-bom.php');
  33. yield self::prepareTestCase('test-utf8.case2.php', 'test-utf8.case2-bom.php');
  34. yield ['<?php '];
  35. }
  36. /**
  37. * @return array{string, null|string, \SplFileInfo}
  38. */
  39. private static function prepareTestCase(string $expectedFilename, ?string $inputFilename = null): array
  40. {
  41. $expectedFile = self::getTestFile(__DIR__.'/../../Fixtures/FixerTest/encoding/'.$expectedFilename);
  42. $inputFile = null !== $inputFilename ? self::getTestFile(__DIR__.'/../../Fixtures/FixerTest/encoding/'.$inputFilename) : null;
  43. return [
  44. file_get_contents($expectedFile->getRealPath()),
  45. null !== $inputFile ? file_get_contents($inputFile->getRealPath()) : null,
  46. $inputFile ?? $expectedFile,
  47. ];
  48. }
  49. }