Exemplo n.º 1
0
 public function testSendReturnsFalse()
 {
     $notifier = $this->getNotifier();
     $notification = new Notification();
     $notification->setBody('The notification body');
     $this->assertFalse($notifier->send($notification));
 }
Exemplo n.º 2
0
 public function notify(Commit $commit)
 {
     if (!$this->notifier) {
         return;
     }
     $notification = new Notification();
     $notification->setTitle($commit->getProject()->getName());
     $notification->setBody($this->format($this->format, $commit));
     $this->notifier->send($notification);
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $container = new Container();
     $verbose = OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity();
     $strategy = $container->getChainStrategy();
     $executor = $container->getExecutor(!$input->getOption('no-cache'), $verbose, $input->getOption('timeout'));
     $serviceManager = $container->getServiceManager($verbose);
     $notifier = NotifierFactory::create();
     $output->writeln("<info>Creating builds...</info>");
     $jobs = $strategy->getJobs($input->getOption("project-path"));
     $output->writeln(sprintf("<info>%s builds created</info>", count($jobs)));
     $exitCode = 0;
     try {
         foreach ($jobs as $job) {
             $output->writeln(sprintf("\n<info>Running job %s</info>\n", $job->getDescription()));
             $serviceManager->start($job);
             $strategy->prepareJob($job);
             $success = $executor->test($job, $input->getArgument('cmd'));
             $exitCode += $success == 0 ? 0 : 1;
             if ($input->getOption('notify')) {
                 $notification = new Notification();
                 $notification->setBody(sprintf('Test results for %s on %s', $container->getNaming()->getProjectName($input->getOption('project-path')), $job->getDescription()));
                 $notification->setTitle($success == 0 ? 'Tests passed' : 'Tests failed');
                 $notifier->send($notification);
             }
             $serviceManager->stop($job);
         }
     } catch (\Exception $e) {
         // Try stop last builds
         if (isset($job)) {
             $serviceManager->stop($job);
         }
         // We do not deal with exception (Console Component do it well),
         // we just catch it to allow cleaner to be runned even if one of the build failed hard
         // Simulation of a finally for php < 5.6 :-°
     }
     $container->getVacuum()->clean($input->getOption("project-path"), $input->getOption("keep"));
     if (isset($e)) {
         throw $e;
     }
     return $exitCode;
 }
 public function testSendThrowsExceptionWhenNotificationHasAnEmptyBody()
 {
     $notifier = $this->getNotifier();
     $notification = new Notification();
     $notification->setBody('');
     try {
         $notifier->send($notification);
         $this->fail('Expected a InvalidNotificationException');
     } catch (\Exception $e) {
         $this->assertInstanceOf('Joli\\JoliNotif\\Exception\\InvalidNotificationException', $e);
     }
 }