44
55namespace DrevOps \VortexInstaller \Command ;
66
7+ use DrevOps \VortexInstaller \Runner \ExecutableFinderAwareInterface ;
8+ use DrevOps \VortexInstaller \Runner \ExecutableFinderAwareTrait ;
79use DrevOps \VortexInstaller \Runner \ProcessRunner ;
10+ use DrevOps \VortexInstaller \Runner \ProcessRunnerAwareInterface ;
11+ use DrevOps \VortexInstaller \Runner \ProcessRunnerAwareTrait ;
812use DrevOps \VortexInstaller \Runner \RunnerInterface ;
913use DrevOps \VortexInstaller \Task \Task ;
1014use DrevOps \VortexInstaller \Utils \Tui ;
1620/**
1721 * Check requirements command.
1822 */
19- class CheckRequirementsCommand extends Command {
23+ class CheckRequirementsCommand extends Command implements ProcessRunnerAwareInterface, ExecutableFinderAwareInterface {
24+
25+ use ProcessRunnerAwareTrait;
26+ use ExecutableFinderAwareTrait;
2027
2128 const string OPTION_ONLY = 'only ' ;
2229
@@ -44,11 +51,6 @@ class CheckRequirementsCommand extends Command {
4451 */
4552 public static $ defaultName = 'check-requirements ' ;
4653
47- /**
48- * The process runner.
49- */
50- protected ProcessRunner $ runner ;
51-
5254 /**
5355 * Present tools.
5456 *
@@ -83,7 +85,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8385 $ only = $ input ->getOption (static ::OPTION_ONLY );
8486 $ requirements = $ this ->validateRequirements ($ only ? array_map (trim (...), explode (', ' , (string ) $ only )) : NULL );
8587
86- $ this ->runner = $ this ->getRunner ();
88+ $ this ->processRunner ?? = $ this ->getProcessRunner ();
8789 $ this ->present = [];
8890 $ this ->missing = [];
8991
@@ -146,7 +148,7 @@ protected function validateRequirements(?array $only): array {
146148 if ($ only !== NULL ) {
147149 $ unknown = array_diff ($ only , static ::REQUIREMENTS );
148150 if (!empty ($ unknown )) {
149- throw new \InvalidArgumentException (sprintf (' Unknown requirements: %s. Available : %s. ' , implode (', ' , $ unknown ), implode (', ' , static ::REQUIREMENTS )));
151+ throw new \InvalidArgumentException (sprintf (" Unknown requirements: %s. \n Available : %s." , implode (', ' , $ unknown ), implode (', ' , static ::REQUIREMENTS )));
150152 }
151153 }
152154
@@ -274,37 +276,37 @@ protected function checkPygmy(): bool {
274276
275277 $ version = $ this ->getCommandVersion ('pygmy version ' );
276278
277- $ this ->runner ->run ('pygmy status ' );
278- if ($ this ->runner ->getExitCode () === RunnerInterface::EXIT_SUCCESS ) {
279+ $ this ->processRunner ->run ('pygmy status ' );
280+ if ($ this ->processRunner ->getExitCode () === RunnerInterface::EXIT_SUCCESS ) {
279281 $ this ->present ['Pygmy ' ] = $ version ;
280282 return TRUE ;
281283 }
282284
283- $ this ->runner ->run ('docker ps --format "{{.Names}}" | grep -q amazeeio ' );
285+ $ this ->processRunner ->run ('docker ps --format "{{.Names}}" | grep -q amazeeio ' );
284286 // @phpstan-ignore-next-line notIdentical.alwaysFalse
285- if ($ this ->runner ->getExitCode () === RunnerInterface::EXIT_SUCCESS ) {
287+ if ($ this ->processRunner ->getExitCode () === RunnerInterface::EXIT_SUCCESS ) {
286288 $ this ->present ['Pygmy ' ] = $ version ;
287289 return TRUE ;
288290 }
289291
290292 $ this ->missing ['Pygmy ' ] = 'Run: pygmy up ' ;
293+
291294 return FALSE ;
292295 }
293296
294297 /**
295298 * Check if a command exists.
296299 */
297300 protected function commandExists (string $ command ): bool {
298- $ this ->runner ->run (sprintf ('command -v %s ' , escapeshellarg ($ command )));
299- return $ this ->runner ->getExitCode () === RunnerInterface::EXIT_SUCCESS ;
301+ return $ this ->getExecutableFinder ()->find ($ command ) !== NULL ;
300302 }
301303
302304 /**
303305 * Check if Docker Compose exists.
304306 */
305307 protected function dockerComposeExists (): bool {
306- $ this ->runner ->run ('docker compose version ' );
307- if ($ this ->runner ->getExitCode () === RunnerInterface::EXIT_SUCCESS ) {
308+ $ this ->processRunner ->run ('docker compose version ' );
309+ if ($ this ->processRunner ->getExitCode () === RunnerInterface::EXIT_SUCCESS ) {
308310 return TRUE ;
309311 }
310312
@@ -320,36 +322,17 @@ protected function dockerComposeExists(): bool {
320322 * Number of lines to retrieve from the output. Defaults to 1.
321323 */
322324 protected function getCommandVersion (string $ command , int $ lines = 1 ): string {
323- $ this ->runner ->run ($ command );
324- $ raw_output = $ this ->runner ->getOutput (FALSE , $ lines );
325+ $ this ->processRunner ->run ($ command );
326+ $ raw_output = $ this ->processRunner ->getOutput (FALSE , $ lines );
325327 $ output = trim (is_string ($ raw_output ) ? $ raw_output : implode (PHP_EOL , $ raw_output ));
326328 return empty ($ output ) ? 'Available ' : $ output ;
327329 }
328330
329331 /**
330- * Get the process runner instance.
331- *
332- * Factory method to create the runner, allowing tests to override this
333- * to inject mocks via setRunner().
334- *
335- * @return \DrevOps\VortexInstaller\Runner\ProcessRunner
336- * The process runner instance.
337- */
338- protected function getRunner (): ProcessRunner {
339- // Return already-set runner if available (for testing).
340- return $ this ->runner ?? (new ProcessRunner ())->disableLog ()->disableStreaming ();
341- }
342-
343- /**
344- * Set the process runner instance.
345- *
346- * Allows dependency injection for testing.
347- *
348- * @param \DrevOps\VortexInstaller\Runner\ProcessRunner $runner
349- * The process runner instance.
332+ * {@inheritdoc}
350333 */
351- public function setRunner ( ProcessRunner $ runner ): void {
352- $ this ->runner = $ runner ;
334+ public function getProcessRunner ( ): ProcessRunner {
335+ return $ this ->processRunner ?? ( new ProcessRunner ())-> disableLog ()-> disableStreaming () ;
353336 }
354337
355338}
0 commit comments