bug #35641 [Process] throw when PhpProcess::fromShellCommandLine() is used (Guikingone)

This PR was merged into the 4.4 branch.

Discussion
----------

[Process] throw when PhpProcess::fromShellCommandLine() is used

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #35637
| License       | MIT
| Doc PR        | None

Close #35638

Final PR (rebased and tests added)

Commits
-------

7f6d71c2a3 refactor(Process): fromShellCommandLine
This commit is contained in:
Fabien Potencier 2020-02-08 08:06:43 +01:00
commit 2d89ed1f26
2 changed files with 20 additions and 0 deletions

View File

@ -11,6 +11,7 @@
namespace Symfony\Component\Process;
use Symfony\Component\Process\Exception\LogicException;
use Symfony\Component\Process\Exception\RuntimeException;
/**
@ -49,6 +50,14 @@ class PhpProcess extends Process
parent::__construct($php, $cwd, $env, $script, $timeout);
}
/**
* {@inheritdoc}
*/
public static function fromShellCommandline(string $command, string $cwd = null, array $env = null, $input = null, ?float $timeout = 60)
{
throw new LogicException(sprintf('The "%s()" method cannot be called when using "%s".', __METHOD__, self::class));
}
/**
* Sets the path to the PHP binary to use.
*

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Process\Tests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Process\Exception\LogicException;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\PhpProcess;
@ -60,4 +61,14 @@ PHP;
$process->run();
$this->assertEquals($expected, $process->getOutput());
}
public function testProcessCannotBeCreatedUsingFromShellCommandLine()
{
static::expectException(LogicException::class);
static::expectExceptionMessage('The "Symfony\Component\Process\PhpProcess::fromShellCommandline()" method cannot be called when using "Symfony\Component\Process\PhpProcess".');
PhpProcess::fromShellCommandline(<<<PHP
<?php echo 'Hello World!';
PHP
);
}
}