[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/metamta/adapter/ -> PhabricatorMailImplementationTestAdapter.php (source)

   1  <?php
   2  
   3  /**
   4   * Mail adapter that doesn't actually send any email, for writing unit tests
   5   * against.
   6   */
   7  final class PhabricatorMailImplementationTestAdapter
   8    extends PhabricatorMailImplementationAdapter {
   9  
  10    private $guts = array();
  11    private $config;
  12  
  13    public function __construct(array $config = array()) {
  14      $this->config = $config;
  15    }
  16  
  17    public function setFrom($email, $name = '') {
  18      $this->guts['from'] = $email;
  19      $this->guts['from-name'] = $name;
  20      return $this;
  21    }
  22  
  23    public function addReplyTo($email, $name = '') {
  24      if (empty($this->guts['reply-to'])) {
  25        $this->guts['reply-to'] = array();
  26      }
  27      $this->guts['reply-to'][] = array(
  28        'email' => $email,
  29        'name'  => $name,
  30      );
  31      return $this;
  32    }
  33  
  34    public function addTos(array $emails) {
  35      foreach ($emails as $email) {
  36        $this->guts['tos'][] = $email;
  37      }
  38      return $this;
  39    }
  40  
  41    public function addCCs(array $emails) {
  42      foreach ($emails as $email) {
  43        $this->guts['ccs'][] = $email;
  44      }
  45      return $this;
  46    }
  47  
  48    public function addAttachment($data, $filename, $mimetype) {
  49      $this->guts['attachments'][] = array(
  50        'data' => $data,
  51        'filename' => $filename,
  52        'mimetype' => $mimetype,
  53      );
  54      return $this;
  55    }
  56  
  57    public function addHeader($header_name, $header_value) {
  58      $this->guts['headers'][] = array($header_name, $header_value);
  59      return $this;
  60    }
  61  
  62    public function setBody($body) {
  63      $this->guts['body'] = $body;
  64      return $this;
  65    }
  66  
  67    public function setHTMLBody($html_body) {
  68      $this->guts['html-body'] = $html_body;
  69      return $this;
  70    }
  71  
  72    public function setSubject($subject) {
  73      $this->guts['subject'] = $subject;
  74      return $this;
  75    }
  76  
  77    public function supportsMessageIDHeader() {
  78      return idx($this->config, 'supportsMessageIDHeader', true);
  79    }
  80  
  81    public function send() {
  82      if (!empty($this->guts['fail-permanently'])) {
  83        throw new PhabricatorMetaMTAPermanentFailureException(
  84          'Unit Test (Permanent)');
  85      }
  86  
  87      if (!empty($this->guts['fail-temporarily'])) {
  88        throw new Exception(
  89          'Unit Test (Temporary)');
  90      }
  91  
  92      $this->guts['did-send'] = true;
  93      return true;
  94    }
  95  
  96    public function getGuts() {
  97      return $this->guts;
  98    }
  99  
 100    public function setFailPermanently($fail) {
 101      $this->guts['fail-permanently'] = $fail;
 102      return $this;
 103    }
 104  
 105    public function setFailTemporarily($fail) {
 106      $this->guts['fail-temporarily'] = $fail;
 107      return $this;
 108    }
 109  
 110  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1