Skip to content

Commit

Permalink
Prepare bundle for unit testing (#14)
Browse files Browse the repository at this point in the history
* Add phpunit

* Apply fixes from StyleCI

* Fix version matrix

* Compatibility with Swiftmailer 6.0.1

* Upgrade phpunit

* Make style ci happy
  • Loading branch information
foaly-nr1 authored Apr 3, 2018
1 parent 62ccd1e commit 0334180
Show file tree
Hide file tree
Showing 18 changed files with 126 additions and 44 deletions.
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
language: php

matrix:
include:
- php: 7.1
env: SWIFT_VERSION=~6.0.0
- php: 7.1
env: SWIFT_VERSION=~5.4.0

before_script:
- composer require "swiftmailer/swiftmailer:${SWIFT_VERSION}" --no-update
- composer install --no-interaction --dev
3 changes: 3 additions & 0 deletions Factory/GmailMessageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,15 @@ public function createFromGmailApiMessage(\Google_Service_Gmail_Message $gmailAp
switch ($header->getName()) {
case 'From':
$message->setFrom($header->getValue() ?? '');

break;
case 'To':
$message->setTo($header->getValue() ?? '');

break;
case 'Subject':
$message->setSubject($header->getValue() ?? '');

break;
}
$headerNames[] = $header->getName();
Expand Down
4 changes: 2 additions & 2 deletions Model/Collection/GmailDomain.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(string $domain)
*
* @return GmailDomain
*/
public function addGmailUser(GmailUserInterface $user): GmailDomain
public function addGmailUser(GmailUserInterface $user): self
{
$this->gmailUsers->attach($user);

Expand All @@ -51,7 +51,7 @@ public function addGmailUser(GmailUserInterface $user): GmailDomain
*
* @return GmailDomain
*/
public function removeGmailUser(GmailUserInterface $user): GmailDomain
public function removeGmailUser(GmailUserInterface $user): self
{
$this->gmailUsers->detach($user);

Expand Down
4 changes: 2 additions & 2 deletions Model/Collection/GmailLabelCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct()
*
* @return GmailLabelCollection
*/
public function addLabel(GmailLabelInterface $label): GmailLabelCollection
public function addLabel(GmailLabelInterface $label): self
{
$this->labels->attach($label);

Expand All @@ -42,7 +42,7 @@ public function addLabel(GmailLabelInterface $label): GmailLabelCollection
*
* @return GmailLabelCollection
*/
public function removeLabel(GmailLabelInterface $label): GmailLabelCollection
public function removeLabel(GmailLabelInterface $label): self
{
$this->labels->detach($label);

Expand Down
4 changes: 2 additions & 2 deletions Model/Collection/GmailMessageCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct()
*
* @return GmailMessageCollection
*/
public function addMessage(GmailMessageInterface $message): GmailMessageCollection
public function addMessage(GmailMessageInterface $message): self
{
$this->messages->attach($message);

Expand All @@ -41,7 +41,7 @@ public function addMessage(GmailMessageInterface $message): GmailMessageCollecti
*
* @return GmailMessageCollection
*/
public function removeMessage(GmailMessageInterface $message): GmailMessageCollection
public function removeMessage(GmailMessageInterface $message): self
{
$this->messages->detach($message);

Expand Down
6 changes: 3 additions & 3 deletions Model/GmailHistoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface GmailHistoryInterface
*
* @return GmailHistoryInterface
*/
public function setUserId(string $userId): GmailHistoryInterface;
public function setUserId(string $userId): self;

/**
* @return string
Expand All @@ -27,7 +27,7 @@ public function getUserId(): string;
*
* @return GmailHistoryInterface
*/
public function setDomain(string $domain): GmailHistoryInterface;
public function setDomain(string $domain): self;

/**
* @return string
Expand All @@ -39,7 +39,7 @@ public function getDomain(): string;
*
* @return GmailHistoryInterface
*/
public function setHistoryId(int $historyId): GmailHistoryInterface;
public function setHistoryId(int $historyId): self;

/**
* @return int
Expand Down
6 changes: 3 additions & 3 deletions Model/GmailIdsInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface GmailIdsInterface
*
* @return GmailIdsInterface
*/
public function setUserId(string $userId): GmailIdsInterface;
public function setUserId(string $userId): self;

/**
* @return string
Expand All @@ -27,7 +27,7 @@ public function getUserId(): string;
*
* @return GmailIdsInterface
*/
public function setDomain(string $domain): GmailIdsInterface;
public function setDomain(string $domain): self;

/**
* @return string
Expand All @@ -42,7 +42,7 @@ public function getDomain(): string;
*
* @return GmailIdsInterface
*/
public function setGmailIds(array $gmailIds): GmailIdsInterface;
public function setGmailIds(array $gmailIds): self;

/**
* The limit parameter allows you to retrieve a slice of the gmailIds.
Expand Down
6 changes: 3 additions & 3 deletions Model/GmailLabelInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface GmailLabelInterface
*
* @return GmailLabelInterface
*/
public function setUserId(string $userId): GmailLabelInterface;
public function setUserId(string $userId): self;

/**
* @return string
Expand All @@ -27,7 +27,7 @@ public function getUserId(): string;
*
* @return GmailLabelInterface
*/
public function setDomain(string $domain): GmailLabelInterface;
public function setDomain(string $domain): self;

/**
* @return string
Expand All @@ -39,7 +39,7 @@ public function getDomain(): string;
*
* @return GmailLabelInterface
*/
public function setName(string $name): GmailLabelInterface;
public function setName(string $name): self;

/**
* @return string
Expand Down
37 changes: 20 additions & 17 deletions Model/GmailMessageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@ interface GmailMessageInterface
* @see https://developers.google.com/gmail/api/guides/labels
*/
const LABEL_UNREAD = 'UNREAD';

const LABEL_INBOX = 'INBOX';

const LABEL_SENT = 'SENT';

const LABEL_TRASH = 'TRASH';

/**
* @param string $gmailId
*
* @return GmailMessageInterface
*/
public function setGmailId(string $gmailId): GmailMessageInterface;
public function setGmailId(string $gmailId): self;

/**
* @return string
Expand All @@ -37,7 +40,7 @@ public function getGmailId(): string;
*
* @return GmailMessageInterface
*/
public function setDomain(string $domain): GmailMessageInterface;
public function setDomain(string $domain): self;

/**
* @return string
Expand All @@ -49,7 +52,7 @@ public function getDomain(): string;
*
* @return GmailMessageInterface
*/
public function setThreadId(string $threadId): GmailMessageInterface;
public function setThreadId(string $threadId): self;

/**
* @return string
Expand All @@ -61,7 +64,7 @@ public function getThreadId(): string;
*
* @return GmailMessageInterface
*/
public function setHistoryId(string $historyId): GmailMessageInterface;
public function setHistoryId(string $historyId): self;

/**
* @return string
Expand All @@ -73,7 +76,7 @@ public function getHistoryId(): string;
*
* @return GmailMessageInterface
*/
public function setUserId(string $userId): GmailMessageInterface;
public function setUserId(string $userId): self;

/**
* @return string
Expand All @@ -88,7 +91,7 @@ public function getUserId(): string;
*
* @return GmailMessageInterface
*/
public function setTo(string $to): GmailMessageInterface;
public function setTo(string $to): self;

/**
* @return string
Expand All @@ -111,7 +114,7 @@ public function getToCanonical(): string;
*
* @return GmailMessageInterface
*/
public function setFrom(string $from): GmailMessageInterface;
public function setFrom(string $from): self;

/**
* @return string
Expand All @@ -138,7 +141,7 @@ public function getReplyAllRecipients(): string;
*
* @return GmailMessageInterface
*/
public function setSentAt(\DateTimeInterface $sentAt): GmailMessageInterface;
public function setSentAt(\DateTimeInterface $sentAt): self;

/**
* @return \DateTimeInterface
Expand All @@ -150,7 +153,7 @@ public function getSentAt(): \DateTimeInterface;
*
* @return GmailMessageInterface
*/
public function setSubject(string $subject): GmailMessageInterface;
public function setSubject(string $subject): self;

/**
* @return string
Expand All @@ -162,7 +165,7 @@ public function getSubject(): string;
*
* @return GmailMessageInterface
*/
public function setSnippet(string $snippet): GmailMessageInterface;
public function setSnippet(string $snippet): self;

/**
* @return string
Expand All @@ -180,7 +183,7 @@ public function getSnippet(): string;
*
* @return GmailMessageInterface
*/
public function setBodyPlainTextFromApiMessage(\Google_Service_Gmail_Message $gmailApiMessage): GmailMessageInterface;
public function setBodyPlainTextFromApiMessage(\Google_Service_Gmail_Message $gmailApiMessage): self;

/**
* @return string
Expand All @@ -192,7 +195,7 @@ public function getBodyPlainText(): string;
*
* @return GmailMessageInterface
*/
public function setBodyPlainText(string $bodyPlainText): GmailMessageInterface;
public function setBodyPlainText(string $bodyPlainText): self;

/**
* Set from a \Google_Service_Gmail_Message (from the API).
Expand All @@ -205,14 +208,14 @@ public function setBodyPlainText(string $bodyPlainText): GmailMessageInterface;
*
* @return GmailMessageInterface
*/
public function setBodyHtmlFromApiMessage(\Google_Service_Gmail_Message $gmailApiMessage): GmailMessageInterface;
public function setBodyHtmlFromApiMessage(\Google_Service_Gmail_Message $gmailApiMessage): self;

/**
* @param string $bodyHtml
*
* @return GmailMessageInterface
*/
public function setBodyHtml(string $bodyHtml): GmailMessageInterface;
public function setBodyHtml(string $bodyHtml): self;

/**
* @return string
Expand All @@ -224,7 +227,7 @@ public function getBodyHtml(): string;
*
* @return GmailMessageInterface
*/
public function addLabel(GmailLabelInterface $label): GmailMessageInterface;
public function addLabel(GmailLabelInterface $label): self;

/**
* @return \Traversable
Expand All @@ -236,12 +239,12 @@ public function getLabels(): \Traversable;
*
* @return GmailMessageInterface
*/
public function removeLabel(GmailLabelInterface $label): GmailMessageInterface;
public function removeLabel(GmailLabelInterface $label): self;

/**
* @return GmailMessageInterface
*/
public function clearLabels(): GmailMessageInterface;
public function clearLabels(): self;

/**
* @param string $name
Expand Down
8 changes: 4 additions & 4 deletions Model/GmailUserInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function getUserId(): string;
*
* @return GmailUserInterface
*/
public function setUserId(string $userId): GmailUserInterface;
public function setUserId(string $userId): self;

/**
* @return string
Expand All @@ -32,7 +32,7 @@ public function getPrimaryEmailAddress(): string;
*
* @return GmailUserInterface
*/
public function setPrimaryEmailAddress(string $primaryEmailAddress): GmailUserInterface;
public function setPrimaryEmailAddress(string $primaryEmailAddress): self;

/**
* @return string[]
Expand All @@ -44,14 +44,14 @@ public function getEmailAliases(): array;
*
* @return GmailUserInterface
*/
public function addEmailAlias(string $emailAlias): GmailUserInterface;
public function addEmailAlias(string $emailAlias): self;

/**
* @param string $emailAlias
*
* @return GmailUserInterface
*/
public function removeEmailAlias(string $emailAlias): GmailUserInterface;
public function removeEmailAlias(string $emailAlias): self;

/**
* Should return email aliases, plus primary email address.
Expand Down
5 changes: 5 additions & 0 deletions Services/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
class Directory
{
const MODE_RESOLVE_PRIMARY_ONLY = 0;

const MODE_RESOLVE_ALIASES_ONLY = 1;

const MODE_RESOLVE_PRIMARY_PLUS_ALIASES = 2;

/**
Expand Down Expand Up @@ -178,14 +180,17 @@ public function resolveUserIdFromEmail(string $email, int $mode)
switch ($mode) {
case self::MODE_RESOLVE_PRIMARY_ONLY:
$gmailUser = $this->getGmailDomain()->findGmailUserByPrimaryEmail($email);

break;

case self::MODE_RESOLVE_ALIASES_ONLY:
$gmailUser = $this->getGmailDomain()->findGmailUserByEmailAlias($email);

break;

case self::MODE_RESOLVE_PRIMARY_PLUS_ALIASES:
$gmailUser = $this->getGmailDomain()->findGmailUserByEmail($email);

break;

default:
Expand Down
Loading

0 comments on commit 0334180

Please sign in to comment.