Esempio n. 1
0
 public function testSendReturnsFalse()
 {
     $notifier = $this->getNotifier();
     $notification = new Notification();
     $notification->setBody('The notification body');
     $this->assertFalse($notifier->send($notification));
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 protected function configureProcess(ProcessBuilder $processBuilder, Notification $notification)
 {
     $script = 'display notification "' . $notification->getBody() . '"';
     if ($notification->getTitle()) {
         $script .= ' with title "' . $notification->getTitle() . '"';
     }
     $processBuilder->add('-e');
     $processBuilder->add($script);
 }
Esempio n. 3
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);
 }
Esempio n. 4
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;
 }
 /**
  * {@inheritdoc}
  */
 public function send(Notification $notification)
 {
     if (!$notification->getBody()) {
         throw new InvalidNotificationException($notification, 'Notification body can not be empty');
     }
     $builder = new ProcessBuilder();
     if (self::SUPPORT_BINARY_PROVIDED === $this->support && $this instanceof BinaryProvider) {
         $dir = rtrim($this->getRootDir(), '/') . '/';
         $embeddedBinary = $dir . $this->getEmbeddedBinary();
         if (PharExtractor::isLocatedInsideAPhar($embeddedBinary)) {
             $embeddedBinary = PharExtractor::extractFile($embeddedBinary);
             foreach ($this->getExtraFiles() as $file) {
                 PharExtractor::extractFile($dir . $file);
             }
         }
         $builder->setPrefix($embeddedBinary);
     } else {
         $builder->setPrefix($this->getBinary());
     }
     $this->configureProcess($builder, $notification);
     $process = $builder->getProcess();
     $process->run();
     return $process->isSuccessful();
 }
Esempio n. 6
0
 /**
  * {@inheritdoc}
  */
 protected function configureProcess(ProcessBuilder $processBuilder, Notification $notification)
 {
     if ($notification->getIcon()) {
         $processBuilder->add('--icon');
         $processBuilder->add($notification->getIcon());
     }
     if ($notification->getTitle()) {
         $processBuilder->add($notification->getTitle());
     }
     $processBuilder->add($notification->getBody());
 }
 /**
  * {@inheritdoc}
  */
 protected function configureProcess(ProcessBuilder $processBuilder, Notification $notification)
 {
     $processBuilder->add('-message');
     $processBuilder->add($notification->getBody());
     if ($notification->getTitle()) {
         $processBuilder->add('-title');
         $processBuilder->add($notification->getTitle());
     }
     if ($notification->getIcon() && version_compare(OsHelper::getMacOSVersion(), '10.9.0', '>=')) {
         $processBuilder->add('-appIcon');
         $processBuilder->add($notification->getIcon());
     }
 }
 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);
     }
 }
 /**
  * @param array $record
  *
  * @return bool
  *
  * @throws \Joli\JoliNotif\Exception\InvalidNotificationException
  */
 protected function write(array $record)
 {
     $this->notification->setTitle(sprintf('[%s] %s', Logger::getLevelName($this->level), $this->name))->setBody(addslashes($record['formatted']));
     return $this->notifier && $this->notifier->send($this->notification);
 }