[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

/vendor/symfony/console/Symfony/Component/Console/Tester/ -> ApplicationTester.php (source)

   1  <?php
   2  
   3  /*
   4   * This file is part of the Symfony package.
   5   *
   6   * (c) Fabien Potencier <fabien@symfony.com>
   7   *
   8   * For the full copyright and license information, please view the LICENSE
   9   * file that was distributed with this source code.
  10   */
  11  
  12  namespace Symfony\Component\Console\Tester;
  13  
  14  use Symfony\Component\Console\Application;
  15  use Symfony\Component\Console\Input\ArrayInput;
  16  use Symfony\Component\Console\Input\InputInterface;
  17  use Symfony\Component\Console\Output\OutputInterface;
  18  use Symfony\Component\Console\Output\StreamOutput;
  19  
  20  /**
  21   * Eases the testing of console applications.
  22   *
  23   * When testing an application, don't forget to disable the auto exit flag:
  24   *
  25   *     $application = new Application();
  26   *     $application->setAutoExit(false);
  27   *
  28   * @author Fabien Potencier <fabien@symfony.com>
  29   */
  30  class ApplicationTester
  31  {
  32      private $application;
  33      private $input;
  34      private $output;
  35  
  36      /**
  37       * Constructor.
  38       *
  39       * @param Application $application An Application instance to test.
  40       */
  41      public function __construct(Application $application)
  42      {
  43          $this->application = $application;
  44      }
  45  
  46      /**
  47       * Executes the application.
  48       *
  49       * Available options:
  50       *
  51       *  * interactive: Sets the input interactive flag
  52       *  * decorated:   Sets the output decorated flag
  53       *  * verbosity:   Sets the output verbosity flag
  54       *
  55       * @param array $input   An array of arguments and options
  56       * @param array $options An array of options
  57       *
  58       * @return int The command exit code
  59       */
  60      public function run(array $input, $options = array())
  61      {
  62          $this->input = new ArrayInput($input);
  63          if (isset($options['interactive'])) {
  64              $this->input->setInteractive($options['interactive']);
  65          }
  66  
  67          $this->output = new StreamOutput(fopen('php://memory', 'w', false));
  68          if (isset($options['decorated'])) {
  69              $this->output->setDecorated($options['decorated']);
  70          }
  71          if (isset($options['verbosity'])) {
  72              $this->output->setVerbosity($options['verbosity']);
  73          }
  74  
  75          return $this->application->run($this->input, $this->output);
  76      }
  77  
  78      /**
  79       * Gets the display returned by the last execution of the application.
  80       *
  81       * @param bool $normalize Whether to normalize end of lines to \n or not
  82       *
  83       * @return string The display
  84       */
  85      public function getDisplay($normalize = false)
  86      {
  87          rewind($this->output->getStream());
  88  
  89          $display = stream_get_contents($this->output->getStream());
  90  
  91          if ($normalize) {
  92              $display = str_replace(PHP_EOL, "\n", $display);
  93          }
  94  
  95          return $display;
  96      }
  97  
  98      /**
  99       * Gets the input instance used by the last execution of the application.
 100       *
 101       * @return InputInterface The current input instance
 102       */
 103      public function getInput()
 104      {
 105          return $this->input;
 106      }
 107  
 108      /**
 109       * Gets the output instance used by the last execution of the application.
 110       *
 111       * @return OutputInterface The current output instance
 112       */
 113      public function getOutput()
 114      {
 115          return $this->output;
 116      }
 117  }


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1