Mercurial > hg > cmmr2012-drupal-site
comparison vendor/consolidation/site-process/tests/src/CommandTesterTrait.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
4:a9cd425dd02b | 5:12f9dff5fda9 |
---|---|
1 <?php | |
2 | |
3 namespace Consolidation\SiteProcess; | |
4 | |
5 use Symfony\Component\Console\Output\BufferedOutput; | |
6 | |
7 trait CommandTesterTrait | |
8 { | |
9 /** @var string */ | |
10 protected $appName; | |
11 | |
12 /** @var string */ | |
13 protected $appVersion; | |
14 | |
15 /** | |
16 * Instantiate a new runner | |
17 */ | |
18 public function setupCommandTester($appName, $appVersion) | |
19 { | |
20 // Define our invariants for our test | |
21 $this->appName = $appName; | |
22 $this->appVersion = $appVersion; | |
23 } | |
24 | |
25 /** | |
26 * Prepare our $argv array; put the app name in $argv[0] followed by | |
27 * the command name and all command arguments and options. | |
28 * | |
29 * @param array $functionParameters should usually be func_get_args() | |
30 * @param int $leadingParameterCount the number of function parameters | |
31 * that are NOT part of argv. Default is 2 (expected content and | |
32 * expected status code). | |
33 */ | |
34 protected function argv($functionParameters, $leadingParameterCount = 2) | |
35 { | |
36 $argv = $functionParameters; | |
37 $argv = array_slice($argv, $leadingParameterCount); | |
38 array_unshift($argv, $this->appName); | |
39 | |
40 return $argv; | |
41 } | |
42 | |
43 /** | |
44 * Simulated front controller | |
45 */ | |
46 protected function execute($argv, $commandClasses, $configurationFile = false) | |
47 { | |
48 // Define a global output object to capture the test results | |
49 $output = new BufferedOutput(); | |
50 | |
51 // We can only call `Runner::execute()` once; then we need to tear down. | |
52 $runner = new \Robo\Runner($commandClasses); | |
53 if ($configurationFile) { | |
54 $runner->setConfigurationFilename($configurationFile); | |
55 } | |
56 $statusCode = $runner->execute($argv, $this->appName, $this->appVersion, $output); | |
57 | |
58 // Destroy our container so that we can call $runner->execute() again for the next test. | |
59 \Robo\Robo::unsetContainer(); | |
60 | |
61 // Return the output and status code. | |
62 return [trim($output->fetch()), $statusCode]; | |
63 } | |
64 } |