-
Notifications
You must be signed in to change notification settings - Fork 460
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #535 from bapcltd/issue/526
empty array is falsey and triggers exception
- Loading branch information
Showing
4 changed files
with
147 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
/** | ||
* Live Mailbox - PHPUnit tests. | ||
* | ||
* Runs tests on a live mailbox | ||
* | ||
* @author BAPCLTD-Marv | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace PhpImap; | ||
|
||
use ParagonIE\HiddenString\HiddenString; | ||
|
||
/** | ||
* @psalm-type MAILBOX_ARGS = array{ | ||
* 0:HiddenString, | ||
* 1:HiddenString, | ||
* 2:HiddenString, | ||
* 3:string, | ||
* 4?:string | ||
* } | ||
*/ | ||
trait LiveMailboxTestingTrait | ||
{ | ||
/** | ||
* Provides constructor arguments for a live mailbox. | ||
* | ||
* @psalm-return MAILBOX_ARGS[] | ||
*/ | ||
public function MailBoxProvider(): array | ||
{ | ||
$sets = []; | ||
|
||
$imapPath = \getenv('PHPIMAP_IMAP_PATH'); | ||
$login = \getenv('PHPIMAP_LOGIN'); | ||
$password = \getenv('PHPIMAP_PASSWORD'); | ||
|
||
if (\is_string($imapPath) && \is_string($login) && \is_string($password)) { | ||
$sets['CI ENV'] = [new HiddenString($imapPath), new HiddenString($login), new HiddenString($password, true, true), \sys_get_temp_dir()]; | ||
} | ||
|
||
return $sets; | ||
} | ||
|
||
/** | ||
* Get instance of Mailbox, pre-set to a random mailbox. | ||
* | ||
* @param string $attachmentsDir | ||
* @param string $serverEncoding | ||
* | ||
* @return mixed[] | ||
* | ||
* @psalm-return array{0:Mailbox, 1:string, 2:HiddenString} | ||
*/ | ||
protected function getMailbox(HiddenString $imapPath, HiddenString $login, HiddenString $password, $attachmentsDir, $serverEncoding = 'UTF-8') | ||
{ | ||
$mailbox = new Mailbox($imapPath->getString(), $login->getString(), $password->getString(), $attachmentsDir, $serverEncoding); | ||
|
||
$random = 'test-box-'.\date('c').\bin2hex(\random_bytes(4)); | ||
|
||
$mailbox->createMailbox($random); | ||
|
||
$mailbox->switchMailbox($random, false); | ||
|
||
return [$mailbox, $random, $imapPath]; | ||
} | ||
|
||
/** | ||
* @psalm-param MAILBOX_ARGS $mailbox_args | ||
* | ||
* @return mixed[] | ||
* | ||
* @psalm-return array{0:Mailbox, 1:string, 2:HiddenString} | ||
*/ | ||
protected function getMailboxFromArgs(array $mailbox_args): array | ||
{ | ||
list($path, $username, $password, $attachments_dir) = $mailbox_args; | ||
|
||
return $this->getMailbox( | ||
$path, | ||
$username, | ||
$password, | ||
$attachments_dir, | ||
isset($mailbox_args[4]) ? $mailbox_args[4] : 'UTF-8' | ||
); | ||
} | ||
} |