Пример #1
0
 /**
  * @param Config        $config
  * @param \Closure|null $helperSetManipulator
  *
  * @return TestableApplication
  */
 protected function getApplication(Config $config = null, $helperSetManipulator = null)
 {
     if (null === $config) {
         $config = new Config('/home/user', '/temp/gush');
     }
     $adapterFactory = new AdapterFactory();
     $adapterFactory->register('github', 'GitHub', new TestAdapterFactory('github'));
     $adapterFactory->register('github_enterprise', 'GitHub Enterprise', new TestAdapterFactory('github_enterprise'));
     $adapterFactory->register('jira', 'Jira', new TestIssueTrackerFactory());
     $helperSetClosure = function (HelperSet $helperSet) use($helperSetManipulator) {
         // Fake all system helpers to prevent actual execution
         $helperSet->set(new FilesystemHelper($this->getNewTmpFolder('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;
 }
Пример #2
0
 public function testCannotCreateUnregisteredAdapter()
 {
     $this->setExpectedException('InvalidArgumentException', 'No Adapter with name "test2" is registered.');
     $this->adapterFactory->createRepositoryManager('test2', [], $this->config);
 }