File tree 1 file changed +35
-0
lines changed
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)
532
532
}
533
533
return $ container ->get ($ service );
534
534
}
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
+ }
535
570
536
571
/**
537
572
* @return \Symfony\Component\HttpKernel\Profiler\Profile
You can’t perform that action at this time.
0 commit comments