AbstractDifferTestCase.php 1.6 KB

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