Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tests/CommandLine/Source/TestOption.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,14 @@ final class TestOption
* @var string
*/
public const OUTPUT_FORMAT = 'output-format';

/**
* @var string
*/
public const FIX = 'fix';

/**
* @var string
*/
public const MEMORY_LIMIT = 'memory-limit';
}
78 changes: 71 additions & 7 deletions tests/CommandLine/WorkerCommandLineFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,82 @@ public function test(array $optionValues, array $paths, string $expectedCommand)

public static function provideData(): Iterator
{
$expectedCommandLinesString = self::createExpectedCommandLinesString();
yield 'no options, single path' => [[], ['src'], self::wrap('', "'src'")];

yield [[], ['src'], $expectedCommandLinesString];
yield 'output-format is excluded' => [
[TestOption::OUTPUT_FORMAT => 'console'],
['src'],
self::wrap('', "'src'"),
];

// output-format is excluded, so it must not change the result
yield [[TestOption::OUTPUT_FORMAT => 'console'], ['src'], $expectedCommandLinesString];
yield 'true bool option becomes a flag' => [
[TestOption::FIX => true],
['src'],
self::wrap('--fix', "'src'"),
];

yield 'false bool option is omitted' => [
[TestOption::FIX => false],
['src'],
self::wrap('', "'src'"),
];

yield 'null option is omitted' => [
[TestOption::MEMORY_LIMIT => null],
['src'],
self::wrap('', "'src'"),
];

yield 'memory-limit uses the assign form' => [
[TestOption::MEMORY_LIMIT => '-1'],
['src'],
self::wrap('--memory-limit=-1', "'src'"),
];

yield 'string option keeps the escaped value' => [
['some-option' => 'value'],
['src'],
self::wrap("--some-option 'value'", "'src'"),
];

yield 'multiple paths are all escaped' => [[], ['src', 'tests'], self::wrap('', "'src' 'tests'")];

yield 'framework global options are excluded' => [
['no-interaction' => true, 'verbose' => true, 'ansi' => true, 'help' => true],
['src'],
self::wrap('', "'src'"),
];
}

private static function createExpectedCommandLinesString(): string
public function testProjectConfigFileIsPassedRightAfterWorkerName(): void
{
$commandLineString = "'" . PHP_BINARY . "' '" . self::DUMMY_MAIN_SCRIPT . "'";
$workerCommandLine = $this->workerCommandLineFactory->create(
self::DUMMY_MAIN_SCRIPT,
'worker',
'ecs.php',
[],
['src'],
'identifier',
2000
);

$expectedCommand = "'" . PHP_BINARY . "' '" . self::DUMMY_MAIN_SCRIPT
. "' worker --config 'ecs.php' --port 2000 --identifier 'identifier' 'src' --output-format 'json' --no-ansi";

$this->assertSame($expectedCommand, $workerCommandLine);
}

/**
* Assemble the expected command line: options sit before --port, paths after --identifier.
*/
private static function wrap(string $options, string $paths): string
{
$command = "'" . PHP_BINARY . "' '" . self::DUMMY_MAIN_SCRIPT . "' worker";

if ($options !== '') {
$command .= ' ' . $options;
}

return $commandLineString . " worker --port 2000 --identifier 'identifier' 'src' --output-format 'json' --no-ansi";
return $command . " --port 2000 --identifier 'identifier' " . $paths . " --output-format 'json' --no-ansi";
}
}
Loading