EncodingFixerTest.php 1.6 KB

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