Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / symfony / console / Symfony / Component / Console / Tester / ApplicationTester.php
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  * @author Fabien Potencier <fabien@symfony.com>
24  */
25 class ApplicationTester
26 {
27     private $application;
28     private $input;
29     private $output;
30
31     /**
32      * Constructor.
33      *
34      * @param Application $application An Application instance to test.
35      */
36     public function __construct(Application $application)
37     {
38         $this->application = $application;
39     }
40
41     /**
42      * Executes the application.
43      *
44      * Available options:
45      *
46      *  * interactive: Sets the input interactive flag
47      *  * decorated:   Sets the output decorated flag
48      *  * verbosity:   Sets the output verbosity flag
49      *
50      * @param array $input   An array of arguments and options
51      * @param array $options An array of options
52      *
53      * @return integer The command exit code
54      */
55     public function run(array $input, $options = array())
56     {
57         $this->input = new ArrayInput($input);
58         if (isset($options['interactive'])) {
59             $this->input->setInteractive($options['interactive']);
60         }
61
62         $this->output = new StreamOutput(fopen('php://memory', 'w', false));
63         if (isset($options['decorated'])) {
64             $this->output->setDecorated($options['decorated']);
65         }
66         if (isset($options['verbosity'])) {
67             $this->output->setVerbosity($options['verbosity']);
68         }
69
70         return $this->application->run($this->input, $this->output);
71     }
72
73     /**
74      * Gets the display returned by the last execution of the application.
75      *
76      * @return string The display
77      */
78     public function getDisplay()
79     {
80         rewind($this->output->getStream());
81
82         return stream_get_contents($this->output->getStream());
83     }
84
85     /**
86      * Gets the input instance used by the last execution of the application.
87      *
88      * @return InputInterface The current input instance
89      */
90     public function getInput()
91     {
92         return $this->input;
93     }
94
95     /**
96      * Gets the output instance used by the last execution of the application.
97      *
98      * @return OutputInterface The current output instance
99      */
100     public function getOutput()
101     {
102         return $this->output;
103     }
104 }