function it_does_not_generate_interface_when_prompt_is_answered_with_no(IO $io, ExampleEvent $exampleEvent, SuiteEvent $suiteEvent, GeneratorManager $generator)
 {
     $io->askConfirmation('Would you like me to generate an interface `Example\\ExampleClass` for you?')->willReturn(false);
     $this->afterExample($exampleEvent);
     $this->afterSuite($suiteEvent);
     $generator->generate(Argument::cetera())->shouldNotHaveBeenCalled();
     $suiteEvent->markAsWorthRerunning()->shouldNotHaveBeenCalled();
 }
 /**
  * @param SuiteEvent $event
  */
 public function afterSuite(SuiteEvent $event)
 {
     if (!$this->io->isCodeGenerationEnabled()) {
         return;
     }
     foreach ($this->exceptions as $exception) {
         $resource = $this->resources->createResource($exception->getCollaboratorName());
         if ($this->resourceIsInSpecNamespace($exception, $resource)) {
             continue;
         }
         if ($this->io->askConfirmation(sprintf('Would you like me to generate an interface `%s` for you?', $exception->getCollaboratorName()))) {
             $this->generator->generate($resource, 'interface');
             $event->markAsWorthRerunning();
         }
     }
 }
 public function afterSuite(SuiteEvent $event)
 {
     if (!$this->io->isCodeGenerationEnabled()) {
         return;
     }
     if (!$this->io->isFakingEnabled()) {
         return;
     }
     foreach ($this->nullMethods as $methodString => $failedCall) {
         $failedCall['expected'] = array_unique($failedCall['expected']);
         if (count($failedCall['expected']) > 1) {
             continue;
         }
         $expected = current($failedCall['expected']);
         $class = $failedCall['class'];
         $message = sprintf('Do you want me to make `%s()` always return %s for you?', $methodString, var_export($expected, true));
         try {
             $resource = $this->resources->createResource($class);
         } catch (\RuntimeException $exception) {
             continue;
         }
         if ($this->io->askConfirmation($message)) {
             $this->generator->generate($resource, 'returnConstant', array('method' => $failedCall['method'], 'expected' => $expected));
             $event->markAsWorthRerunning();
         }
     }
 }
 function it_generates_the_method_signature_when_user_says_yes_at_prompt(ConsoleIO $io, ExampleEvent $event, SuiteEvent $suiteEvent, MethodNotFoundException $exception, Resource $resource, GeneratorManager $generator)
 {
     $io->askConfirmation(Argument::any())->willReturn(true);
     $exception->getClassname()->willReturn('spec\\PhpSpec\\Listener\\DoubleOfInterface');
     $exception->getMethodName()->willReturn('aMethod');
     $this->afterExample($event);
     $this->afterSuite($suiteEvent);
     $generator->generate($resource, 'method-signature', Argument::any())->shouldHaveBeenCalled();
 }
 /**
  * @param SuiteEvent $event
  */
 public function afterSuite(SuiteEvent $event)
 {
     foreach ($this->interfaces as $interface => $methods) {
         try {
             $resource = $this->resources->createResource($interface);
         } catch (ResourceCreationException $e) {
             continue;
         }
         foreach ($methods as $method => $arguments) {
             if ($this->io->askConfirmation(sprintf(self::PROMPT, $interface, $method))) {
                 $this->generator->generate($resource, 'method-signature', array('name' => $method, 'arguments' => $this->getRealArguments($arguments)));
                 $event->markAsWorthRerunning();
             }
         }
     }
 }
 function it_invokes_method_body_generation_when_prompt_is_answered_yes(MethodCallEvent $methodCallEvent, ExampleEvent $exampleEvent, IO $io, GeneratorManager $generatorManager, ResourceManager $resourceManager, ResourceInterface $resource, SuiteEvent $event)
 {
     $io->askConfirmation(Argument::any())->willReturn(true);
     $resourceManager->createResource(Argument::any())->willReturn($resource);
     $methodCallEvent->getSubject()->willReturn(new \StdClass());
     $methodCallEvent->getMethod()->willReturn('myMethod');
     $this->afterMethodCall($methodCallEvent);
     $this->afterExample($exampleEvent);
     $this->afterSuite($event);
     $generatorManager->generate($resource, 'returnConstant', array('method' => 'myMethod', 'expected' => 100))->shouldHaveBeenCalled();
 }