Skip to content

Commit

Permalink
Merge pull request #194 from facile-it/pass-through
Browse files Browse the repository at this point in the history
Pass through
  • Loading branch information
Jean85 authored Mar 2, 2023
2 parents 9d5c968 + 161a6f6 commit 619606b
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 16 deletions.
27 changes: 14 additions & 13 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.6.0@e784128902dfe01d489c4123d69918a9f3c1eac5">
<files psalm-version="5.7.7@e028ba46ba0d7f9a78bc3201c251e137383e145f">
<file src="src/Configuration/PHPUnitConfig.php">
<DocblockTypeContradiction>
<code>$extension-&gt;attributes</code>
<code><![CDATA[$extension->attributes]]></code>
</DocblockTypeContradiction>
<RedundantConditionGivenDocblockType>
<code>$extension-&gt;attributes?-&gt;getNamedItem('class')</code>
<code><![CDATA[$extension->attributes?->getNamedItem('class')]]></code>
</RedundantConditionGivenDocblockType>
</file>
<file src="src/Configuration/ParallelConfiguration.php">
<MixedArgument>
<code>$input-&gt;getArgument('stringFilter')</code>
<code>$input-&gt;getOption('chunk-size')</code>
<code>$input-&gt;getOption('configuration') ?? '.'</code>
<code>$input-&gt;getOption('logo')</code>
<code>$input-&gt;getOption('parallel')</code>
<code>$input-&gt;getOption('testsuite')</code>
<code><![CDATA[$input->getArgument('stringFilter')]]></code>
<code><![CDATA[$input->getOption('chunk-size')]]></code>
<code><![CDATA[$input->getOption('configuration') ?? '.']]></code>
<code><![CDATA[$input->getOption('logo')]]></code>
<code><![CDATA[$input->getOption('parallel')]]></code>
<code><![CDATA[$input->getOption('pass-through')]]></code>
<code><![CDATA[$input->getOption('testsuite')]]></code>
</MixedArgument>
</file>
<file src="src/Coverage/CoverageFetcher.php">
Expand All @@ -25,8 +26,8 @@
</file>
<file src="src/File/Cleaner.php">
<MixedArgument>
<code>$file-&gt;getRealPath()</code>
<code>$file-&gt;getRealPath()</code>
<code><![CDATA[$file->getRealPath()]]></code>
<code><![CDATA[$file->getRealPath()]]></code>
</MixedArgument>
<MixedAssignment>
<code>$file</code>
Expand All @@ -39,12 +40,12 @@
</file>
<file src="src/Filter/Filter.php">
<PossiblyNullOperand>
<code>$fileNode-&gt;nodeValue</code>
<code><![CDATA[$fileNode->nodeValue]]></code>
</PossiblyNullOperand>
</file>
<file src="src/Process/CommandLine.php">
<PossiblyNullOperand>
<code>$option-&gt;getValue()</code>
<code><![CDATA[$option->getValue()]]></code>
</PossiblyNullOperand>
</file>
<file src="src/Process/SymfonyProcessWrapper.php">
Expand Down
1 change: 1 addition & 0 deletions src/Command/ParallelCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ protected function configure(): void
$this->addOption('chunk-size', null, InputOption::VALUE_REQUIRED, 'Number of test files in chunk', 1);
$this->addOption('debug', null, InputOption::VALUE_NONE, 'Print verbose debug output');
$this->addOption('logo', null, InputOption::VALUE_NONE, 'Print the Shark logo at the top');
$this->addOption('pass-through', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Inject options to be passed directly to the underlying PHPUnit processes');

foreach ($this->phpunitOptions as $option) {
$this->addOption(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Paraunit\Configuration\DependencyInjection;

use Paraunit\Configuration\ChunkSize;
use Paraunit\Configuration\PassThrough;
use Paraunit\Configuration\PHPUnitBinFile;
use Paraunit\Configuration\PHPUnitConfig;
use Paraunit\Configuration\TempFilenameFactory;
Expand Down Expand Up @@ -101,6 +102,9 @@ private function configureConfiguration(ContainerBuilder $container): void

$container->autowire(ChunkSize::class)
->setArgument('$chunkSize', '%paraunit.chunk_size%');

$container->register(PassThrough::class)
->setArguments(['%paraunit.pass_through%']);
}

private function configureEventDispatcher(ContainerBuilder $container): void
Expand Down
1 change: 1 addition & 0 deletions src/Configuration/ParallelConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ protected function loadCommandLineOptions(ContainerBuilder $containerBuilder, In
$containerBuilder->setParameter('paraunit.testsuite', $input->getOption('testsuite'));
$containerBuilder->setParameter('paraunit.string_filter', $input->getArgument('stringFilter'));
$containerBuilder->setParameter('paraunit.show_logo', $input->getOption('logo'));
$containerBuilder->setParameter('paraunit.pass_through', $input->getOption('pass-through'));

if ($input->getOption('debug')) {
$this->enableDebugMode($containerBuilder);
Expand Down
19 changes: 19 additions & 0 deletions src/Configuration/PassThrough.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Paraunit\Configuration;

class PassThrough
{
/** @var list<string> */
public readonly array $options;

/**
* @param string[]|null $options
*/
public function __construct(?array $options = [])
{
$this->options = array_values($options ?? []);
}
}
5 changes: 4 additions & 1 deletion src/Process/ProcessFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Paraunit\Configuration\ChunkSize;
use Paraunit\Configuration\EnvVariables;
use Paraunit\Configuration\PassThrough;
use Paraunit\Configuration\PHPUnitConfig;
use Paraunit\Configuration\TempFilenameFactory;
use Paraunit\Coverage\CoverageDriver;
Expand All @@ -23,7 +24,8 @@ public function __construct(
private readonly CommandLine $cliCommand,
PHPUnitConfig $phpunitConfig,
TempFilenameFactory $tempFilenameFactory,
private readonly ChunkSize $chunkSize
private readonly ChunkSize $chunkSize,
private readonly PassThrough $passThrough,
) {
$this->baseCommandLine = array_merge($this->cliCommand->getExecutable(), $this->cliCommand->getOptions($phpunitConfig));
$this->environmentVariables = [
Expand Down Expand Up @@ -57,6 +59,7 @@ public function create(string $testFilePath): Process
$command = array_merge(
$this->baseCommandLine,
[$testFilePath],
$this->passThrough->options,
$this->cliCommand->getSpecificOptions($testFilePath)
);
}
Expand Down
25 changes: 25 additions & 0 deletions tests/PHPT/pass-through.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
Execute the run command with the --pass-through option
--FILE--
<?php

require_once __DIR__ . '/../../src/Bin/paraunit';
--ARGS--
run IntentionalWarningTestStub -c tests/Stub/phpunit_for_stubs.xml --pass-through=--stop-on-warning
--EXPECTF--
PARAUNIT v%s
by Francesco Panina, Alessandro Lai & Shark Dev Team @ Facile.it
W %w 1


Execution time -- 00:00:%d

Executed: 1 test classes, 1 tests

Warnings output:

1) Tests\Stub\IntentionalWarningTestStub::testWithIntentionalWarning
This is an intentional warning

1 files with WARNINGS:
Tests\Stub\IntentionalWarningTestStub::testWithIntentionalWarning
2 changes: 2 additions & 0 deletions tests/Unit/Configuration/CoverageConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public function testBuildContainerWithCoverageSettings(string $inputOption, stri
'ansi',
'logo',
'chunk-size',
'pass-through',
];

foreach ($options as $optionName) {
Expand Down Expand Up @@ -197,6 +198,7 @@ public function testBuildContainerWithColoredTextToConsoleCoverage(): void
'crap4j',
'php',
'chunk-size',
'pass-through',
];

foreach ($options as $optionName) {
Expand Down
10 changes: 8 additions & 2 deletions tests/Unit/Process/ProcessFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Paraunit\Configuration\ChunkSize;
use Paraunit\Configuration\EnvVariables;
use Paraunit\Configuration\PassThrough;
use Paraunit\Configuration\PHPUnitConfig;
use Paraunit\Configuration\TempFilenameFactory;
use Paraunit\Coverage\CoverageDriver;
Expand Down Expand Up @@ -44,7 +45,8 @@ public function testCreateProcess(): void
$cliCommand->reveal(),
$phpUnitConfig->reveal(),
$tempFilenameFactory->reveal(),
$this->mockChunkSize(false)
$this->mockChunkSize(false),
new PassThrough(['--one', '--two=yes']),
);

$processWrapper = $factory->create('TestTest.php');
Expand All @@ -60,6 +62,8 @@ public function testCreateProcess(): void
$commandLine = $processWrapper->getCommandLine();
$this->assertStringContainsString('TestTest2.php', $commandLine);
$this->assertStringContainsString('--specific=value-for-TestTest2.php', $commandLine);
$this->assertStringContainsString('--one', $commandLine);
$this->assertStringContainsString('--two=yes', $commandLine);
}

#[DataProvider('coverageDriverDataProvider')]
Expand All @@ -84,6 +88,7 @@ public function testCreateProcessWithCoverageDriver(CoverageDriver $coverageDriv
$phpUnitConfig->reveal(),
$tempFilenameFactory->reveal(),
$this->prophesize(ChunkSize::class)->reveal(),
new PassThrough(),
);

$this->assertEquals([
Expand Down Expand Up @@ -126,7 +131,8 @@ public function testCreateProcessChunked(): void
$cliCommand->reveal(),
$phpUnitConfig->reveal(),
$tempFilenameFactory->reveal(),
$this->mockChunkSize(true)
$this->mockChunkSize(true),
new PassThrough(),
);

$processWrapper = $factory->create('phpunit.xml');
Expand Down

0 comments on commit 619606b

Please sign in to comment.