Skip to content

Commit

Permalink
ProcessFactory must drop testsuite if chunked (#274]
Browse files Browse the repository at this point in the history
  • Loading branch information
ilario-pierbattista committed Oct 2, 2024
1 parent daeccfa commit dfe2cc7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 23 deletions.
6 changes: 4 additions & 2 deletions src/Process/CommandLine.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function getExecutable(): array
*
* @return string[]
*/
public function getOptions(PHPUnitConfig $config): array
public function getOptions(PHPUnitConfig $config, array $excludedPhpunitOptions = []): array

Check failure on line 42 in src/Process/CommandLine.php

View workflow job for this annotation

GitHub Actions / PHPStan

Method Paraunit\Process\CommandLine::getOptions() has parameter $excludedPhpunitOptions with no value type specified in iterable type array.
{
$options = [];

Expand All @@ -59,7 +59,9 @@ public function getOptions(PHPUnitConfig $config): array
]);

foreach ($config->getPhpunitOptions() as $phpunitOption) {
$options[] = $this->buildPhpunitOptionString($phpunitOption);
if(! in_array($phpunitOption->getName(), $excludedPhpunitOptions, true)) {
$options[] = $this->buildPhpunitOptionString($phpunitOption);
}
}

return $options;
Expand Down
12 changes: 6 additions & 6 deletions src/Process/ProcessFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,40 @@ class ProcessFactory implements ProcessFactoryInterface
/** @var CommandLine */
private $cliCommand;

/** @var string[] */
private $baseCommandLine;

/** @var string[] */
private $environmentVariables;

/** @var ChunkSize */
private $chunkSize;

/** @var PHPUnitConfig */
private $phpunitConfig;

public function __construct(
CommandLine $cliCommand,
PHPUnitConfig $phpunitConfig,
TempFilenameFactory $tempFilenameFactory,
ChunkSize $chunkSize
) {
$this->cliCommand = $cliCommand;
$this->baseCommandLine = array_merge($this->cliCommand->getExecutable(), $this->cliCommand->getOptions($phpunitConfig));
$this->environmentVariables = [
EnvVariables::LOG_DIR => $tempFilenameFactory->getPathForLog(),
];
$this->chunkSize = $chunkSize;
$this->phpunitConfig = $phpunitConfig;
}

public function create(string $testFilePath): AbstractParaunitProcess
{
if ($this->chunkSize->isChunked()) {
$command = array_merge(
$this->baseCommandLine,
array_merge($this->cliCommand->getExecutable(), $this->cliCommand->getOptions($this->phpunitConfig, ['testsuite'])),
['--configuration=' . $testFilePath],
$this->cliCommand->getSpecificOptions($testFilePath)
);
} else {
$command = array_merge(
$this->baseCommandLine,
array_merge($this->cliCommand->getExecutable(), $this->cliCommand->getOptions($this->phpunitConfig)),
[$testFilePath],
$this->cliCommand->getSpecificOptions($testFilePath)
);
Expand Down
14 changes: 0 additions & 14 deletions tests/Functional/Runner/ChunkFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,6 @@

class ChunkFileTest extends BaseIntegrationTestCase
{
public function testChunkedPlusTestSuiteOptions(): void
{
$this->setOption('chunk-size', '2');
$this->setOption('testsuite', 'stubs');
$this->setOption('debug', '1');
$this->loadContainer();

$this->executeRunner();

$output = $this->getConsoleOutput();
$this->assertStringNotContainsString('--testsuite', $output->getOutput());
$this->assertStringContainsString('--configuration', $output->getOutput());
}

public function testChunkedAllStubsSuite(): void
{
$chunkCount = 8;
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Process/ProcessFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Paraunit\Process\AbstractParaunitProcess;
use Paraunit\Process\CommandLine;
use Paraunit\Process\ProcessFactory;
use Prophecy\Argument;
use Tests\BaseUnitTestCase;

class ProcessFactoryTest extends BaseUnitTestCase
Expand Down Expand Up @@ -64,7 +65,7 @@ public function testCreateProcessChunked(): void
$cliCommand = $this->prophesize(CommandLine::class);
$cliCommand->getExecutable()->willReturn(['sapi', 'executable']);
$cliCommand
->getOptions($phpUnitConfig->reveal())
->getOptions($phpUnitConfig->reveal(), Argument::is(['testsuite']))
->shouldBeCalled()
->willReturn([]);
$cliCommand
Expand Down

0 comments on commit dfe2cc7

Please sign in to comment.