EncodingFixerTest.php 1.6 KB

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