Alex\MailCatcher\Tests\BehatExtensionTest::runBehat PHP Method

runBehat() private method

private runBehat ( $steps, $purge_before_scenario = false, $failServer = false )
    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);
        }
    }