private function runBehat($steps, $purge_before_scenario = false, $failServer = false) { $client = $this->getClient(); $file = tempnam(sys_get_temp_dir(), 'mailcatcher_'); unlink($file); $configFile = $file . '.yml'; $outputFile = $file . '.output'; $file = $file . '.feature'; $content = "Feature: Test\n\n Scenario: Test\n " . implode("\n ", $steps) . "\n"; $contexts = array('Alex\\MailCatcher\\Behat\\MailCatcherContext', 'Alex\\MailCatcher\\Tests\\BehatCustomContext'); if (version_compare(PHP_VERSION, "5.4") > 0) { $contexts[] = 'Alex\\MailCatcher\\Tests\\BehatTraitContext'; } $config = json_encode(array('default' => array('suites' => array('default' => array('paths' => array(sys_get_temp_dir()), 'contexts' => $contexts)), 'extensions' => array('Alex\\MailCatcher\\Behat\\MailCatcherExtension\\Extension' => array('url' => $failServer ? 'http://localhost:1337' : $client->getUrl(), 'purge_before_scenario' => $purge_before_scenario))))); try { $application = new ApplicationFactory(); $behat = $application->createApplication(); $behat->setAutoExit(false); $input = new ArgvInput(array('behat', '--format', 'progress', '--config', $configFile, '--out', $outputFile, $file)); $output = new NullOutput(); file_put_contents($file, $content); file_put_contents($configFile, $config); $result = $behat->run($input, $output); unlink($file); unlink($configFile); } catch (\Exception $exception) { unlink($file); unlink($file . '.config'); $this->fail($exception->getMessage()); $result = null; } if ($result !== 0) { $this->fail('Should finished with status 0, got ' . $result); } }
/** * @group behat */ public function testThatBehatScenariosMeetAcceptanceCriteria() { try { $factory = new BehatFactory(); $arguments = array('-c' => 'tests/behat.yml'); $input = new ArrayInput($arguments); $application = $factory->createApplication(); $this->assertEquals(0, $application->doRun($input, new ConsoleOutput())); } catch (\Exception $exception) { $this->fail($exception->getMessage()); } }
/** * Run behat original command * * @param array $args */ private function runBehatCommand(array $args = array()) { define('BEHAT_BIN_PATH', $this->getContainer()->getParameter('kernel.root_dir') . '/../bin/behat'); function includeIfExists($file) { if (file_exists($file)) { return include $file; } } if (!($loader = includeIfExists($this->getContainer()->getParameter('kernel.root_dir') . '/../vendor/autoload.php')) && !($loader = includeIfExists($container->getParameter('kernel.root_dir') . '/../../../../autoload.php'))) { fwrite(STDERR, 'You must set up the project dependencies, run the following commands:' . PHP_EOL . 'curl -s http://getcomposer.org/installer | php' . PHP_EOL . 'php composer.phar install' . PHP_EOL); exit(1); } $factory = new ApplicationFactory(); $factory->createApplication()->run(new ArrayInput($args)); }