File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -532,6 +532,41 @@ public function grabService($service)
532532 }
533533 return $ container ->get ($ service );
534534 }
535+
536+ /**
537+ * Run Symfony console command, grab response and return as string.
538+ * Recommended to use for integration or functional testing.
539+ *
540+ * ``` php
541+ * <?php
542+ * $result = $I->runSymfonyConsoleCommand('hello:world', '--verbose' => 3]);
543+ * ?>
544+ * ```
545+ *
546+ * @param string $command
547+ * @param mixed[] $params
548+ *
549+ * @return string
550+ *
551+ * @throws \Exception
552+ */
553+ public function runSymfonyConsoleCommand (string $ command , array $ params = [])
554+ {
555+ $ application = new Application ($ this ->kernel );
556+ $ application ->setAutoExit (false );
557+ $ params ['command ' ] = $ command ;
558+
559+ $ input = new ArrayInput ($ params );
560+ $ output = new BufferedOutput ();
561+ $ code = $ application ->run ($ input , $ output );
562+
563+ // return the output, don't use if you used NullOutput()
564+ $ content = $ output ->fetch ();
565+
566+ $ this ->assertEquals (0 , $ code , 'Exit code in ' .$ command .' is not equal 0 : ' .$ content );
567+
568+ return $ content ;
569+ }
535570
536571 /**
537572 * @return \Symfony\Component\HttpKernel\Profiler\Profile
You can’t perform that action at this time.
0 commit comments