Inheritance: extends Symfony\Component\EventDispatcher\Event, implements EventInterface
Esempio n. 1
0
 public function afterExample(ExampleEvent $event)
 {
     $exception = $event->getException();
     if (null !== $exception && $exception instanceof ClassNotFoundException) {
         if (in_array($exception->getClassname(), $this->proposedClasses)) {
             return;
         }
         $this->proposedClasses[] = $exception->getClassname();
         if (null === ($ioTemp = $this->io->cutTemp())) {
             if ("\n" !== $this->io->getLastWrittenMessage()) {
                 $this->io->writeln();
             }
         }
         if ($this->io->askConfirmation('Do you want me to create this class for you?')) {
             $classname = $exception->getClassname();
             $filepath = $this->path . str_replace('\\', DIRECTORY_SEPARATOR, $classname) . '.php';
             $path = dirname($filepath);
             if (!is_dir($path)) {
                 mkdir($path, 0777, true);
             }
             file_put_contents($filepath, $this->getClassContentFor($classname));
             $this->io->writeln(sprintf("\n<info>class <value>%s</value> has been created.</info>", $classname), 6);
         }
         $this->io->writeln();
         if (null !== $ioTemp) {
             $this->io->writeTemp($ioTemp);
         }
     }
 }
 public function afterExample(ExampleEvent $event)
 {
     $exception = $event->getException();
     if (null !== $exception && $exception instanceof MethodNotFoundException) {
         if (null === ($ioTemp = $this->io->cutTemp())) {
             if ("\n" !== $this->io->getLastWrittenMessage()) {
                 $this->io->writeln();
             }
         }
         $shortcut = get_class($exception->getSubject()) . '::' . $exception->getMethod();
         if (in_array($shortcut, $this->proposedMethods)) {
             return;
         }
         $this->proposedMethods[] = $shortcut;
         if ($this->io->askConfirmation('Do you want me to create this method for you?')) {
             $class = new \ReflectionClass($exception->getSubject());
             $method = $exception->getMethod();
             $content = file_get_contents($class->getFileName());
             $content = preg_replace('/}[ \\n]*$/', $this->getMethodContentFor($method) . "\n}\n", $content);
             file_put_contents($class->getFileName(), $content);
             $this->io->writeln(sprintf("\n<info>Method <value>%s::%s()</value> has been created.</info>", $class->getName(), $method), 6);
         }
         $this->io->writeln();
         if (null !== $ioTemp) {
             $this->io->writeTemp($ioTemp);
         }
     }
 }
Esempio n. 3
0
 public function afterExample(ExampleEvent $event)
 {
     $this->globalResult = max($this->globalResult, $event->getResult());
     switch ($event->getResult()) {
         case ExampleEvent::PASSED:
             $this->passedEvents[] = $event;
             break;
         case ExampleEvent::PENDING:
             $this->pendingEvents[] = $event;
             break;
         case ExampleEvent::FAILED:
             $this->failedEvents[] = $event;
             break;
         case ExampleEvent::BROKEN:
             $this->brokenEvents[] = $event;
             break;
     }
 }
Esempio n. 4
0
 protected function printException(ExampleEvent $event)
 {
     if (null === ($exception = $event->getException())) {
         return;
     }
     $title = str_replace('\\', DIRECTORY_SEPARATOR, $event->getSpecification()->getTitle());
     $title = str_pad($title, 50, ' ', STR_PAD_RIGHT);
     $exception->cause = $event->getExample()->getFunction();
     $message = $this->presenter->presentException($exception, $this->io->isVerbose());
     if (ExampleEvent::FAILED === $event->getResult()) {
         $this->io->writeln(sprintf('<failed-bg>%s</failed-bg>', $title));
         $this->io->writeln(sprintf('<lineno>%4d</lineno>  <failed>✘ %s</failed>', $event->getExample()->getFunction()->getStartLine(), $event->getExample()->getTitle()));
         $this->io->writeln(sprintf('<failed>%s</failed>', lcfirst($message)), 6);
     } else {
         $this->io->writeln(sprintf('<broken-bg>%s</broken-bg>', $title));
         $this->io->writeln(sprintf('<lineno>%4d</lineno>  <broken>! %s</broken>', $event->getExample()->getFunction()->getStartLine(), $event->getExample()->getTitle()));
         $this->io->writeln(sprintf('<broken>%s</broken>', lcfirst($message)), 6);
     }
     $this->io->writeln();
 }
Esempio n. 5
0
 protected function printException(ExampleEvent $event, $depth = null)
 {
     if (null === ($exception = $event->getException())) {
         return;
     }
     // TODO: add cause to exception interface
     $exception->cause = $event->getExample()->getFunction();
     $depth = $depth ?: $event->getExample()->getDepth() * 2 + 6;
     $message = $this->presenter->presentException($exception, $this->io->isVerbose());
     if (ExampleEvent::FAILED === $event->getResult()) {
         $this->io->writeln(sprintf('<failed>%s</failed>', lcfirst($message)), $depth);
     } else {
         $this->io->writeln(sprintf('<broken>%s</broken>', lcfirst($message)), $depth);
     }
 }