Gush\Tests\BaseTestCase::getApplication PHP Method

getApplication() protected method

protected getApplication ( Config $config = null, Closure | null $helperSetManipulator = null ) : Gush\Tests\TestableApplication
$config Gush\Config
$helperSetManipulator Closure | null
return Gush\Tests\TestableApplication
    protected function getApplication(Config $config = null, $helperSetManipulator = null)
    {
        if (null === $config) {
            $config = new Config('/home/user');
        }
        $adapterFactory = new AdapterFactory();
        $adapterFactory->register('github', 'GitHub', new TestAdapterFactory('github'));
        $adapterFactory->register('github_enterprise', 'GitHub Enterprise', new TestAdapterFactory('github_enterprise'));
        $adapterFactory->register('gitlab', 'Gitlab', new TestIssueTrackerFactory('gitlab'));
        $helperSetClosure = function (HelperSet $helperSet) use($helperSetManipulator) {
            // Fake all system helpers to prevent actual execution
            $helperSet->set(new FilesystemHelper($this->getNewTmpDirectory('tmp')));
            // Set maximum attempt to prevent inf loop.
            $helperSet->get('gush_question')->setMaxAttempts(2);
            // Use a temp HelperSet to prevent double registering the prophecies (with other parameters)
            // causing failed expectations.
            $tmpHelperSet = new HelperSet();
            if (null !== $helperSetManipulator) {
                $helperSetManipulator($tmpHelperSet);
            }
            if (!$tmpHelperSet->has('process')) {
                $helperSet->set($this->getProcessHelper()->reveal());
            }
            if (!$tmpHelperSet->has('git_config')) {
                $helperSet->set($this->getGitConfigHelper()->reveal());
            }
            if (!$tmpHelperSet->has('git')) {
                $helperSet->set($this->getGitHelper()->reveal());
            }
            foreach ($tmpHelperSet->getIterator() as $helper) {
                $helperSet->set($helper);
            }
        };
        $application = new TestableApplication($adapterFactory, $config, $helperSetClosure);
        $application->setAutoExit(false);
        // Set the IO for Helpers, this should be run before any other listeners!
        $application->getDispatcher()->addListener(GushEvents::DECORATE_DEFINITION, function (ConsoleEvent $event) {
            $command = $event->getCommand();
            $input = $event->getInput();
            $output = $event->getOutput();
            foreach ($command->getHelperSet() as $helper) {
                if ($helper instanceof InputAwareInterface) {
                    $helper->setInput($input);
                }
                if ($helper instanceof OutputAwareInterface) {
                    $helper->setOutput($output);
                }
            }
        }, 255);
        return $application;
    }