AbstractDifferTestCase.php 1.6 KB

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