* @copyright 65Twenty 2015 */ abstract class AbstractCommandTestHelper extends WebTestCase { /** * runCommand * * Creates instance of Application in * test mode and allows commands to be * ran. * * @param Client $client * @param string $command * * @return mixed */ public function runCommand(Client $client, $command) { // Create separate instance of application kernel $application = new Application($client->getKernel()); // Set auto exit application to false $application->setAutoExit(false); // Create a temporary file to contain command output $fp = tmpfile(); // Command input $input = new StringInput($command); // Stream output to temporary file $output = new StreamOutput($fp); // Run command $application->run($input, $output); // Finds first byte in temporary file fseek($fp, 0); // Resets output $output = ''; // Iterates through 'til end of temporary file while (!feof($fp)) { $output = fread($fp, 4096); } // Closes file stream fclose($fp); // Returns final output return $output; } }