AbstractDifferTestCase.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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\Differ;
  12. use PhpCsFixer\Tests\TestCase;
  13. /**
  14. * @author Andreas Möller <am@localheinz.com>
  15. *
  16. * @internal
  17. */
  18. abstract class AbstractDifferTestCase extends TestCase
  19. {
  20. final public function testIsDiffer()
  21. {
  22. $className = preg_replace(
  23. '/Test$/',
  24. '',
  25. str_replace(
  26. 'PhpCsFixer\\Tests\\Differ\\',
  27. 'PhpCsFixer\\Differ\\',
  28. static::class
  29. )
  30. );
  31. $differ = new $className();
  32. static::assertInstanceOf(\PhpCsFixer\Differ\DifferInterface::class, $differ);
  33. }
  34. final protected function oldCode()
  35. {
  36. return <<<'PHP'
  37. <?php
  38. function baz($options)
  39. {
  40. if (!array_key_exists("foo", $options)) {
  41. throw new \InvalidArgumentException();
  42. }
  43. return json_encode($options);
  44. }
  45. PHP;
  46. }
  47. final protected function newCode()
  48. {
  49. return <<<'PHP'
  50. <?php
  51. function baz($options)
  52. {
  53. if (!\array_key_exists("foo", $options)) {
  54. throw new \InvalidArgumentException();
  55. }
  56. return json_encode($options);
  57. }
  58. PHP;
  59. }
  60. }