Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. CommandTester.php

class CommandTester

Eases the testing of console commands.

@author Fabien Potencier <fabien@symfony.com> @author Robin Chalas <robin.chalas@gmail.com>

Hierarchy

  • class \Symfony\Component\Console\Tester\CommandTester uses \Symfony\Component\Console\Tester\TesterTrait

Expanded class hierarchy of CommandTester

File

vendor/symfony/console/Tester/CommandTester.php, line 23

Namespace

Symfony\Component\Console\Tester
View source
class CommandTester {
    use TesterTrait;
    public function __construct(Command $command) {
    }
    
    /**
     * Executes the command.
     *
     * Available execution options:
     *
     *  * interactive:               Sets the input interactive flag
     *  * decorated:                 Sets the output decorated flag
     *  * verbosity:                 Sets the output verbosity flag
     *  * capture_stderr_separately: Make output of stdOut and stdErr separately available
     *
     * @param array $input   An array of command arguments and options
     * @param array $options An array of execution options
     *
     * @return int The command exit code
     */
    public function execute(array $input, array $options = []) : int {
        // set the command name automatically if the application requires
        // this argument and no command name was passed
        if (!isset($input['command']) && null !== ($application = $this->command
            ->getApplication()) && $application->getDefinition()
            ->hasArgument('command')) {
            $input = array_merge([
                'command' => $this->command
                    ->getName(),
            ], $input);
        }
        $this->input = new ArrayInput($input);
        // Use an in-memory input stream even if no inputs are set so that QuestionHelper::ask() does not rely on the blocking STDIN.
        $this->input
            ->setStream(self::createStream($this->inputs));
        if (isset($options['interactive'])) {
            $this->input
                ->setInteractive($options['interactive']);
        }
        if (!isset($options['decorated'])) {
            $options['decorated'] = false;
        }
        $this->initOutput($options);
        return $this->statusCode = $this->command
            ->run($this->input, $this->output);
    }

}

Members

Title Sort descending Modifiers Object type Summary
CommandTester::execute public function Executes the command.
CommandTester::__construct public function
TesterTrait::$captureStreamsIndependently private property
TesterTrait::$input private property
TesterTrait::$inputs private property
TesterTrait::$output private property
TesterTrait::$statusCode private property
TesterTrait::assertCommandIsSuccessful public function
TesterTrait::createStream private static function
TesterTrait::getDisplay public function Gets the display returned by the last execution of the command or application.
TesterTrait::getErrorOutput public function Gets the output written to STDERR by the application.
TesterTrait::getInput public function Gets the input instance used by the last execution of the command or application.
TesterTrait::getOutput public function Gets the output instance used by the last execution of the command or application.
TesterTrait::getStatusCode public function Gets the status code returned by the last execution of the command or application.
TesterTrait::initOutput private function Initializes the output property.
TesterTrait::setInputs public function Sets the user inputs.

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal