Skip to content

Commit

Permalink
bug #35641 [Process] throw when PhpProcess::fromShellCommandLine() is…
Browse files Browse the repository at this point in the history
… 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
-------

7f6d71c refactor(Process): fromShellCommandLine
  • Loading branch information
fabpot committed Feb 8, 2020
2 parents 138439a + 7f6d71c commit 2d89ed1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Symfony/Component/Process/PhpProcess.php
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\Process;

use Symfony\Component\Process\Exception\LogicException;
use Symfony\Component\Process\Exception\RuntimeException;

/**
Expand Down Expand Up @@ -49,6 +50,14 @@ public function __construct(string $script, string $cwd = null, array $env = nul
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.
*
Expand Down
11 changes: 11 additions & 0 deletions src/Symfony/Component/Process/Tests/PhpProcessTest.php
Expand Up @@ -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;

Expand Down Expand Up @@ -60,4 +61,14 @@ public function testPassingPhpExplicitly()
$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
);
}
}

0 comments on commit 2d89ed1

Please sign in to comment.