‪TYPO3CMS  ‪main
AbstractCommandTestCase.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
21 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
22 
23 abstract class ‪AbstractCommandTestCase extends FunctionalTestCase
24 {
25  protected function ‪executeConsoleCommand(string $cmdline, ...‪$args): array
26  {
27  $cmd = vsprintf(PHP_BINARY . ' ' . GeneralUtility::getFileAbsFileName('EXT:core/bin/typo3') . ' ' . $cmdline, array_map('escapeshellarg', ‪$args));
28  $handle = proc_open(
29  $cmd,
30  [
31  // For details, see https://www.php.net/manual/en/function.proc-open
32  ['pipe', 'r'], // stdin is a pipe that the child will read from
33  ['pipe', 'w'], // stdout is a pipe that the child will write to
34  ['pipe', 'w'], // stderr is a pipe that the child will write to
35  ],
36  $pipes
37  );
38 
39  if (!is_resource($handle)) {
40  throw new \Exception('Failed to create proc_open handle', 1700678064);
41  }
42 
43  fclose($pipes[0]);
44  $stdout = stream_get_contents($pipes[1]);
45  fclose($pipes[1]);
46  $stderr = stream_get_contents($pipes[2]);
47  fclose($pipes[2]);
48 
49  $status = proc_close($handle);
50 
51  return [
52  'status' => $status,
53  'stdout' => $stdout,
54  'stderr' => $stderr,
55  ];
56  }
57 }
‪TYPO3\CMS\Core\Tests\Functional\Command\AbstractCommandTestCase\executeConsoleCommand
‪executeConsoleCommand(string $cmdline,... $args)
Definition: AbstractCommandTestCase.php:25
‪$args
‪$args
Definition: validateRstFiles.php:258
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Tests\Functional\Command
Definition: AbstractCommandTestCase.php:18
‪TYPO3\CMS\Core\Tests\Functional\Command\AbstractCommandTestCase
Definition: AbstractCommandTestCase.php:24