[Process] added a deprecation notice

This commit is contained in:
Fabien Potencier 2015-02-05 09:19:53 +01:00
parent 23253c42a2
commit a901ca20bd
4 changed files with 28 additions and 5 deletions

View File

@ -1108,11 +1108,13 @@ class Process
* *
* This content will be passed to the underlying process standard input. * This content will be passed to the underlying process standard input.
* *
* @param string|null $input The content * @param mixed $input The content
* *
* @return self The current Process instance * @return self The current Process instance
* *
* @throws LogicException In case the process is running * @throws LogicException In case the process is running
*
* Passing an object as an input is deprecated since version 2.5 and will be removed in 3.0.
*/ */
public function setInput($input) public function setInput($input)
{ {

View File

@ -167,13 +167,13 @@ class ProcessBuilder
/** /**
* Sets the input of the process. * Sets the input of the process.
* *
* Deprecation: As of Symfony 2.5, this method only accepts string values. * @param mixed $input The input as a string
*
* @param string|null $input The input as a string
* *
* @return ProcessBuilder * @return ProcessBuilder
* *
* @throws InvalidArgumentException In case the argument is invalid * @throws InvalidArgumentException In case the argument is invalid
*
* Passing an object as an input is deprecated since version 2.5 and will be removed in 3.0.
*/ */
public function setInput($input) public function setInput($input)
{ {

View File

@ -83,6 +83,8 @@ class ProcessUtils
* @return string The validated input * @return string The validated input
* *
* @throws InvalidArgumentException In case the input is not valid * @throws InvalidArgumentException In case the input is not valid
*
* Passing an object as an input is deprecated since version 2.5 and will be removed in 3.0.
*/ */
public static function validateInput($caller, $input) public static function validateInput($caller, $input)
{ {
@ -95,6 +97,8 @@ class ProcessUtils
} }
// deprecated as of Symfony 2.5, to be removed in 3.0 // deprecated as of Symfony 2.5, to be removed in 3.0
if (is_object($input) && method_exists($input, '__toString')) { if (is_object($input) && method_exists($input, '__toString')) {
trigger_error('Passing an object as an input is deprecated since version 2.5 and will be removed in 3.0.', E_USER_DEPRECATED);
return (string) $input; return (string) $input;
} }

View File

@ -229,7 +229,24 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
array(null, null), array(null, null),
array('24.5', 24.5), array('24.5', 24.5),
array('input data', 'input data'), array('input data', 'input data'),
// to maintain BC, supposed to be removed in 3.0 );
}
/**
* @dataProvider provideLegacyInputValues
*/
public function testLegacyValidInput($expected, $value)
{
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
$process = $this->getProcess('php -v');
$process->setInput($value);
$this->assertSame($expected, $process->getInput());
}
public function provideLegacyInputValues()
{
return array(
array('stringifiable', new Stringifiable()), array('stringifiable', new Stringifiable()),
); );
} }