IntegrationTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. /**
  29. * {@inheritdoc}
  30. */
  31. protected static function getFixturesDir(): string
  32. {
  33. return __DIR__.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'Integration';
  34. }
  35. /**
  36. * {@inheritdoc}
  37. */
  38. protected static function getTempFile(): string
  39. {
  40. return tempnam(sys_get_temp_dir(), 'PHP-CS-Fixer');
  41. }
  42. protected static function createIntegrationCaseFactory(): IntegrationCaseFactoryInterface
  43. {
  44. return new InternalIntegrationCaseFactory();
  45. }
  46. protected static function assertRevertedOrderFixing(IntegrationCase $case, string $fixedInputCode, string $fixedInputCodeWithReversedFixers): void
  47. {
  48. parent::assertRevertedOrderFixing($case, $fixedInputCode, $fixedInputCodeWithReversedFixers);
  49. $settings = $case->getSettings();
  50. if (!isset($settings['isExplicitPriorityCheck'])) {
  51. static::markTestIncomplete('Missing `isExplicitPriorityCheck` extension setting.');
  52. }
  53. if ($settings['isExplicitPriorityCheck']) {
  54. if ($fixedInputCode === $fixedInputCodeWithReversedFixers) {
  55. if (\in_array($case->getFileName(), [
  56. 'priority'.\DIRECTORY_SEPARATOR.'backtick_to_shell_exec,escape_implicit_backslashes.test',
  57. 'priority'.\DIRECTORY_SEPARATOR.'braces,indentation_type,no_break_comment.test',
  58. 'priority'.\DIRECTORY_SEPARATOR.'standardize_not_equals,binary_operator_spaces.test',
  59. ], true)) {
  60. static::markTestIncomplete(sprintf(
  61. 'Integration test `%s` was defined as explicit priority test, but no priority conflict was detected.'
  62. ."\n".'Either integration test needs to be extended or moved from `priority` to `misc`.'
  63. ."\n".'But don\'t do it blindly - it deserves investigation!',
  64. $case->getFileName()
  65. ));
  66. }
  67. }
  68. static::assertNotSame(
  69. $fixedInputCode,
  70. $fixedInputCodeWithReversedFixers,
  71. sprintf('Test "%s" in "%s" is expected to be priority check.', $case->getTitle(), $case->getFileName())
  72. );
  73. }
  74. }
  75. protected function doTest(IntegrationCase $case): void
  76. {
  77. $requirements = $case->getRequirements();
  78. if (isset($requirements['php<'])) {
  79. $phpUpperLimit = $requirements['php<'];
  80. if (!\is_int($phpUpperLimit)) {
  81. throw new \InvalidArgumentException(sprintf(
  82. 'Expected int value like 50509 for "php<", got "%s". IN "%s".',
  83. get_debug_type($phpUpperLimit).'#'.$phpUpperLimit,
  84. $case->getFileName(),
  85. ));
  86. }
  87. if (\PHP_VERSION_ID >= $phpUpperLimit) {
  88. static::markTestSkipped(sprintf('PHP lower than %d is required for "%s", current "%d".', $phpUpperLimit, $case->getFileName(), \PHP_VERSION_ID));
  89. }
  90. }
  91. parent::doTest($case);
  92. }
  93. }