IntegrationTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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;
  12. use PhpCsFixer\Tests\Test\AbstractIntegrationTestCase;
  13. use PhpCsFixer\Tests\Test\IntegrationCase;
  14. use PhpCsFixer\Tests\Test\InternalIntegrationCaseFactory;
  15. /**
  16. * Test that parses and runs the fixture '*.test' files found in '/Fixtures/Integration'.
  17. *
  18. * @author SpacePossum
  19. *
  20. * @internal
  21. *
  22. * @coversNothing
  23. * @group covers-nothing
  24. */
  25. final class IntegrationTest extends AbstractIntegrationTestCase
  26. {
  27. /**
  28. * {@inheritdoc}
  29. */
  30. protected static function getFixturesDir()
  31. {
  32. return __DIR__.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'Integration';
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. protected static function getTempFile()
  38. {
  39. return self::getFixturesDir().\DIRECTORY_SEPARATOR.'.tmp.php';
  40. }
  41. /**
  42. * {@inheritdoc}
  43. */
  44. protected static function createIntegrationCaseFactory()
  45. {
  46. return new InternalIntegrationCaseFactory();
  47. }
  48. /**
  49. * {@inheritdoc}
  50. */
  51. protected static function assertRevertedOrderFixing(IntegrationCase $case, $fixedInputCode, $fixedInputCodeWithReversedFixers)
  52. {
  53. parent::assertRevertedOrderFixing($case, $fixedInputCode, $fixedInputCodeWithReversedFixers);
  54. $settings = $case->getSettings();
  55. if (!isset($settings['isExplicitPriorityCheck'])) {
  56. static::markTestIncomplete('Missing `isExplicitPriorityCheck` extension setting.');
  57. }
  58. if ($settings['isExplicitPriorityCheck']) {
  59. if ($fixedInputCode === $fixedInputCodeWithReversedFixers) {
  60. if (\in_array($case->getFileName(), [
  61. 'priority'.\DIRECTORY_SEPARATOR.'backtick_to_shell_exec,escape_implicit_backslashes.test',
  62. 'priority'.\DIRECTORY_SEPARATOR.'braces,indentation_type,no_break_comment.test',
  63. 'priority'.\DIRECTORY_SEPARATOR.'standardize_not_equals,binary_operator_spaces.test',
  64. ], true)) {
  65. static::markTestIncomplete(sprintf(
  66. 'Integration test `%s` was defined as explicit priority test, but no priority conflict was detected.'
  67. ."\n".'Either integration test needs to be extended or moved from `priority` to `misc`.'
  68. ."\n".'But don\'t do it blindly - it deserves investigation!',
  69. $case->getFileName()
  70. ));
  71. }
  72. }
  73. static::assertNotSame(
  74. $fixedInputCode,
  75. $fixedInputCodeWithReversedFixers,
  76. sprintf('Test "%s" in "%s" is expected to be priority check.', $case->getTitle(), $case->getFileName())
  77. );
  78. }
  79. }
  80. protected function doTest(IntegrationCase $case)
  81. {
  82. $requirements = $case->getRequirements();
  83. if (isset($requirements['php<'])) {
  84. $phpUpperLimit = $requirements['php<'];
  85. if (!\is_int($phpUpperLimit)) {
  86. throw new \InvalidArgumentException(sprintf(
  87. 'Expected int value like 50509 for "php<", got "%s". IN "%s".',
  88. \is_object($phpUpperLimit) ? \get_class($phpUpperLimit) : \gettype($phpUpperLimit).'#'.$phpUpperLimit,
  89. $case->getFileName()
  90. ));
  91. }
  92. if (\PHP_VERSION_ID >= $phpUpperLimit) {
  93. static::markTestSkipped(sprintf('PHP lower than %d is required for "%s", current "%d".', $phpUpperLimit, $case->getFileName(), \PHP_VERSION_ID));
  94. }
  95. }
  96. parent::doTest($case);
  97. }
  98. }