IntegrationTest.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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;
  13. use PhpCsFixer\Tests\Test\AbstractIntegrationTestCase;
  14. use PhpCsFixer\Tests\Test\IntegrationCase;
  15. use PhpCsFixer\Tests\Test\IntegrationCaseFactoryInterface;
  16. use PhpCsFixer\Tests\Test\InternalIntegrationCaseFactory;
  17. /**
  18. * Test that parses and runs the fixture '*.test' files found in '/Fixtures/Integration'.
  19. *
  20. * @internal
  21. *
  22. * @coversNothing
  23. *
  24. * @group covers-nothing
  25. */
  26. final class IntegrationTest extends AbstractIntegrationTestCase
  27. {
  28. protected static function getFixturesDir(): string
  29. {
  30. return __DIR__.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'Integration';
  31. }
  32. protected static function getTempFile(): string
  33. {
  34. return sys_get_temp_dir().\DIRECTORY_SEPARATOR.'MyClass.php';
  35. }
  36. protected static function createIntegrationCaseFactory(): IntegrationCaseFactoryInterface
  37. {
  38. return new InternalIntegrationCaseFactory();
  39. }
  40. protected static function assertRevertedOrderFixing(IntegrationCase $case, string $fixedInputCode, string $fixedInputCodeWithReversedFixers): void
  41. {
  42. parent::assertRevertedOrderFixing($case, $fixedInputCode, $fixedInputCodeWithReversedFixers);
  43. $settings = $case->getSettings();
  44. if (!isset($settings['isExplicitPriorityCheck'])) {
  45. self::markTestIncomplete('Missing `isExplicitPriorityCheck` extension setting.');
  46. }
  47. if ($settings['isExplicitPriorityCheck']) {
  48. if ($fixedInputCode === $fixedInputCodeWithReversedFixers) {
  49. if (\in_array($case->getFileName(), [
  50. 'priority'.\DIRECTORY_SEPARATOR.'backtick_to_shell_exec,escape_implicit_backslashes.test',
  51. 'priority'.\DIRECTORY_SEPARATOR.'braces,indentation_type,no_break_comment.test',
  52. 'priority'.\DIRECTORY_SEPARATOR.'standardize_not_equals,binary_operator_spaces.test',
  53. ], true)) {
  54. self::markTestIncomplete(sprintf(
  55. 'Integration test `%s` was defined as explicit priority test, but no priority conflict was detected.'
  56. ."\n".'Either integration test needs to be extended or moved from `priority` to `misc`.'
  57. ."\n".'But don\'t do it blindly - it deserves investigation!',
  58. $case->getFileName()
  59. ));
  60. }
  61. }
  62. self::assertNotSame(
  63. $fixedInputCode,
  64. $fixedInputCodeWithReversedFixers,
  65. sprintf('Test "%s" in "%s" is expected to be priority check.', $case->getTitle(), $case->getFileName())
  66. );
  67. }
  68. }
  69. }