AbstractFixerTestBase.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /*
  3. * This file is part of the PHP CS utility.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * This source file is subject to the MIT license that is bundled
  8. * with this source code in the file LICENSE.
  9. */
  10. namespace Symfony\CS\Tests\Fixer;
  11. /**
  12. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  13. */
  14. abstract class AbstractFixerTestBase extends \PHPUnit_Framework_TestCase
  15. {
  16. protected function getFixer()
  17. {
  18. $fixerName = 'Symfony\CS\Fixer'.substr(get_called_class(), strlen(__NAMESPACE__), -strlen('Test'));
  19. return new $fixerName();
  20. }
  21. protected function getTestFile($filename = __FILE__)
  22. {
  23. static $files = array();
  24. if (!isset($files[$filename])) {
  25. $files[$filename] = new \SplFileInfo($filename);
  26. }
  27. return $files[$filename];
  28. }
  29. protected function makeTest($expected, $input = null, \SplFileInfo $file = null)
  30. {
  31. $fixer = $this->getFixer();
  32. $file = $file ?: $this->getTestFile();
  33. if (null !== $input) {
  34. $this->assertSame($expected, $fixer->fix($file, $input));
  35. }
  36. $this->assertSame($expected, $fixer->fix($file, $expected));
  37. }
  38. }