Skip to content

Commit

Permalink
Merge pull request #78 from eliashaeussler/feature/parallel
Browse files Browse the repository at this point in the history
[FEATURE] Enable parallel execution by default
  • Loading branch information
eliashaeussler committed May 17, 2024
2 parents 922afe2 + 481cc10 commit 9314ede
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
namespace EliasHaeussler\PhpCsFixerConfig;

use PhpCsFixer\ConfigInterface;
use PhpCsFixer\Runner;
use Symfony\Component\Finder;

use function array_replace_recursive;
use function class_exists;
use function is_callable;

/**
Expand All @@ -47,6 +49,11 @@ public static function create(): self
$config->getFinder()->ignoreDotFiles(false);
$config->getFinder()->ignoreVCSIgnored(true);

// Enable parallel execution (PHP-CS-Fixer >= 3.57)
if (class_exists(Runner\Parallel\ParallelConfig::class)) {
$config->setParallelConfig(Runner\Parallel\ParallelConfigFactory::detect());
}

return $config;
}

Expand Down
18 changes: 18 additions & 0 deletions tests/src/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@
use EliasHaeussler\PhpCsFixerConfig as Src;
use Generator;
use PhpCsFixer\Config;
use PhpCsFixer\Runner;
use PHPUnit\Framework;
use Symfony\Component\Finder;

use function array_intersect_assoc;
use function class_exists;

/**
* ConfigTest.
Expand Down Expand Up @@ -58,6 +60,22 @@ public function createReturnsConfigWithDefaultRules(): void
self::assertTrue($actual->getRiskyAllowed());
}

#[Framework\Attributes\Test]
public function createReturnsConfigWithParallelExecution(): void
{
// Skip test if class is not available (e.g. when testing with lowest supported version)
if (!class_exists(Runner\Parallel\ParallelConfig::class)) {
self::markTestSkipped('Parallel execution is not available.');
}

$actual = Src\Config::create();

self::assertEquals(
Runner\Parallel\ParallelConfigFactory::detect(),
$actual->getParallelConfig(),
);
}

#[Framework\Attributes\Test]
#[Framework\Attributes\DataProvider('withRulesAddsRuleDataProvider')]
public function withRulesAddsRule(Src\Rules\Rule $rule): void
Expand Down

0 comments on commit 9314ede

Please sign in to comment.