8000 [Process] Fixed issue where $env or $_ENV can contain array values by mmucklo · Pull Request #8123 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Process] Fixed issue where $env or $_ENV can contain array values #8123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
Closed
4 changes: 2 additions & 2 deletions src/Symfony/Component/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function run(InputInterface $input = null, OutputInterface $output = null
}
$statusCode = $e->getCode();

$statusCode = is_numeric($statusCode) && $statusCode ? $statusCode : 1;
$statusCode = $statusCode ? (is_numeric($statusCode) ? (int) $statusCode : 1) : 0;
}

if ($this->autoExit) {
Expand Down Expand Up @@ -193,7 +193,7 @@ public function doRun(InputInterface $input, OutputInterface $output)
$statusCode = $command->run($input, $output);
$this->runningCommand = null;

return is_numeric($statusCode) ? $statusCode : 0;
return $statusCode;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Console/Command/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public function run(InputInterface $input, OutputInterface $output)
$statusCode = $this->execute($input, $output);
}

return is_numeric($statusCode) ? $statusCode : 0;
return is_numeric($statusCode) ? (int) $statusCode : 0;
}

/**
Expand Down
15 changes: 15 additions & 0 deletions src/Symfony/Component/Console/Tests/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,21 @@ public function testRun()
$this->assertSame('called'.PHP_EOL, $tester->getDisplay(), '->run() does not call interact() if -n is passed');
}

public function testRunReturnsIntegerExitCode()
{
$exception = new \Exception('', 4);

$application = $this->getMock('Symfony\Component\Console\Application', array('doRun'));
$application->setAutoExit(false);
$application->expects($this->once())
->method('doRun')
->will($this->throwException($exception));

$exitCode = $application->run(new ArrayInput(array()), new NullOutput());

$this->assertSame(4, $exitCode, '->run() returns integer exit code extracted from raised exception');
}

/**
* @expectedException \LogicException
* @dataProvider getAddingAlreadySetDefinitionElementData
Expand Down
14 changes: 14 additions & 0 deletions src/Symfony/Component/Console/Tests/Command/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,20 @@ public function testRun()
}
}

public function testRunReturnsIntegerExitCode()
{
$command = new \TestCommand();
$exitCode = $command->run(new StringInput(''), new NullOutput());
$this->assertSame(0, $exitCode, '->run() returns integer exit code (treats null as 0)');

$command = $this->getMock('TestCommand', array('execute'));
$command->expects($this->once())
->method('execute')
->will($this->returnValue('2.3'));
$exitCode = $command->run(new StringInput(''), new NullOutput());
$this->assertSame(2, $exitCode, '->run() returns integer exit code (casts numeric to int)');
}

public function testRunReturnsAlwaysInteger()
{
$command = new \TestCommand();
Expand Down
0