forked from barbushin/php-imap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implementing typed properties, adding getter method as workaround for p…
- Loading branch information
1 parent
ba5c977
commit 96f53ca
Showing
1 changed file
with
71 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,16 +15,16 @@ final class MailboxTest extends TestCase | |
/** | ||
* Holds a PhpImap\Mailbox instance. | ||
* | ||
* @var Mailbox | ||
* @var Mailbox|null | ||
*/ | ||
private $mailbox; | ||
private ?Mailbox $mailbox = null; | ||
|
||
/** | ||
* Holds the imap path. | ||
* | ||
* @var string | ||
*/ | ||
private $imapPath = '{imap.example.com:993/imap/ssl/novalidate-cert}INBOX'; | ||
private string $imapPath = '{imap.example.com:993/imap/ssl/novalidate-cert}INBOX'; | ||
|
||
/** | ||
* Holds the imap username. | ||
|
@@ -33,28 +33,28 @@ final class MailboxTest extends TestCase | |
* | ||
* @psalm-var string | ||
*/ | ||
private $login = '[email protected]'; | ||
private string $login = '[email protected]'; | ||
|
||
/** | ||
* Holds the imap user password. | ||
* | ||
* @var string | ||
*/ | ||
private $password = 'v3rY!53cEt&P4sSWöRd$'; | ||
private string $password = 'v3rY!53cEt&P4sSWöRd$'; | ||
|
||
/** | ||
* Holds the relative name of the directory, where email attachments will be saved. | ||
* | ||
* @var string | ||
*/ | ||
private $attachmentsDir = '.'; | ||
private string $attachmentsDir = '.'; | ||
|
||
/** | ||
* Holds the server encoding setting. | ||
* | ||
* @var string | ||
*/ | ||
private $serverEncoding = 'UTF-8'; | ||
private string $serverEncoding = 'UTF-8'; | ||
|
||
/** | ||
* Run before each test is started. | ||
|
@@ -99,9 +99,11 @@ public function testConstructorTrimsPossibleVariables(): void | |
*/ | ||
public function testSetAndGetServerEncoding(): void | ||
{ | ||
$this->mailbox->setServerEncoding('UTF-8'); | ||
$mailbox = $this->getMailbox(); | ||
|
||
$this->assertEquals($this->mailbox->getServerEncoding(), 'UTF-8'); | ||
$mailbox->setServerEncoding('UTF-8'); | ||
|
||
$this->assertEquals($mailbox->getServerEncoding(), 'UTF-8'); | ||
} | ||
|
||
/** | ||
|
@@ -163,13 +165,15 @@ public function serverEncodingProvider(): array | |
*/ | ||
public function testServerEncodingOnlyUseSupportedSettings(bool $bool, string $encoding): void | ||
{ | ||
$mailbox = $this->getMailbox(); | ||
|
||
if ($bool) { | ||
$this->mailbox->setServerEncoding($encoding); | ||
$this->assertEquals($encoding, $this->mailbox->getServerEncoding()); | ||
$mailbox->setServerEncoding($encoding); | ||
$this->assertEquals($encoding, $mailbox->getServerEncoding()); | ||
} else { | ||
$this->expectException(InvalidParameterException::class); | ||
$this->mailbox->setServerEncoding($encoding); | ||
$this->assertNotEquals($encoding, $this->mailbox->getServerEncoding()); | ||
$mailbox->setServerEncoding($encoding); | ||
$this->assertNotEquals($encoding, $mailbox->getServerEncoding()); | ||
} | ||
} | ||
|
||
|
@@ -180,7 +184,7 @@ public function testServerEncodingOnlyUseSupportedSettings(bool $bool, string $e | |
*/ | ||
public function testImapSearchOptionHasADefault(): void | ||
{ | ||
$this->assertEquals($this->mailbox->getImapSearchOption(), 1); | ||
$this->assertEquals($this->getMailbox()->getImapSearchOption(), 1); | ||
} | ||
|
||
/** | ||
|
@@ -192,30 +196,32 @@ public function testSetAndGetImapSearchOption(): void | |
{ | ||
define('ANYTHING', 0); | ||
|
||
$this->mailbox->setImapSearchOption(SE_FREE); | ||
$this->assertEquals($this->mailbox->getImapSearchOption(), 2); | ||
$mailbox = $this->getMailbox(); | ||
|
||
$mailbox->setImapSearchOption(SE_FREE); | ||
$this->assertEquals($mailbox->getImapSearchOption(), 2); | ||
|
||
$this->expectException(InvalidParameterException::class); | ||
$this->mailbox->setImapSearchOption(ANYTHING); | ||
$mailbox->setImapSearchOption(ANYTHING); | ||
|
||
$this->mailbox->setImapSearchOption(SE_UID); | ||
$this->assertEquals($this->mailbox->getImapSearchOption(), 1); | ||
$mailbox->setImapSearchOption(SE_UID); | ||
$this->assertEquals($mailbox->getImapSearchOption(), 1); | ||
} | ||
|
||
/** | ||
* Test, that the imap login can be retrieved. | ||
*/ | ||
public function testGetLogin(): void | ||
{ | ||
$this->assertEquals($this->mailbox->getLogin(), '[email protected]'); | ||
$this->assertEquals($this->getMailbox()->getLogin(), '[email protected]'); | ||
} | ||
|
||
/** | ||
* Test, that the path delimiter has a default value. | ||
*/ | ||
public function testPathDelimiterHasADefault(): void | ||
{ | ||
$this->assertNotEmpty($this->mailbox->getPathDelimiter()); | ||
$this->assertNotEmpty($this->getMailbox()->getPathDelimiter()); | ||
} | ||
|
||
/** | ||
|
@@ -296,11 +302,13 @@ public function testPathDelimiterIsBeingChecked(string $str): void | |
{ | ||
$supported_delimiters = ['.', '/']; | ||
|
||
$mailbox = $this->getMailbox(); | ||
|
||
if (in_array($str, $supported_delimiters)) { | ||
$this->assertTrue($this->mailbox->validatePathDelimiter($str)); | ||
$this->assertTrue($mailbox->validatePathDelimiter($str)); | ||
} else { | ||
$this->expectException(InvalidParameterException::class); | ||
$this->mailbox->setPathDelimiter($str); | ||
$mailbox->setPathDelimiter($str); | ||
} | ||
} | ||
|
||
|
@@ -309,19 +317,21 @@ public function testPathDelimiterIsBeingChecked(string $str): void | |
*/ | ||
public function testSetAndGetPathDelimiter(): void | ||
{ | ||
$this->mailbox->setPathDelimiter('.'); | ||
$this->assertEquals($this->mailbox->getPathDelimiter(), '.'); | ||
$mailbox = $this->getMailbox(); | ||
|
||
$this->mailbox->setPathDelimiter('/'); | ||
$this->assertEquals($this->mailbox->getPathDelimiter(), '/'); | ||
$mailbox->setPathDelimiter('.'); | ||
$this->assertEquals($mailbox->getPathDelimiter(), '.'); | ||
|
||
$mailbox->setPathDelimiter('/'); | ||
$this->assertEquals($mailbox->getPathDelimiter(), '/'); | ||
} | ||
|
||
/** | ||
* Test, that the attachments are not ignored by default. | ||
*/ | ||
public function testGetAttachmentsAreNotIgnoredByDefault(): void | ||
{ | ||
$this->assertEquals($this->mailbox->getAttachmentsIgnore(), false); | ||
$this->assertEquals($this->getMailbox()->getAttachmentsIgnore(), false); | ||
} | ||
|
||
/** | ||
|
@@ -345,8 +355,9 @@ public function attachmentsIgnoreProvider(): array | |
*/ | ||
public function testSetAttachmentsIgnore(bool $paramValue): void | ||
{ | ||
$this->mailbox->setAttachmentsIgnore($paramValue); | ||
$this->assertEquals($this->mailbox->getAttachmentsIgnore(), $paramValue); | ||
$mailbox = $this->getMailbox(); | ||
$mailbox->setAttachmentsIgnore($paramValue); | ||
$this->assertEquals($mailbox->getAttachmentsIgnore(), $paramValue); | ||
} | ||
|
||
/** | ||
|
@@ -396,8 +407,10 @@ public function encodingTestStringsProvider(): array | |
*/ | ||
public function testEncodingToUtf7DecodeBackToUtf8(string $str): void | ||
{ | ||
$utf7_encoded_str = $this->mailbox->encodeStringToUtf7Imap($str); | ||
$utf8_decoded_str = $this->mailbox->decodeStringFromUtf7ImapToUtf8($utf7_encoded_str); | ||
$mailbox = $this->getMailbox(); | ||
|
||
$utf7_encoded_str = $mailbox->encodeStringToUtf7Imap($str); | ||
$utf8_decoded_str = $mailbox->decodeStringFromUtf7ImapToUtf8($utf7_encoded_str); | ||
|
||
$this->assertEquals($utf8_decoded_str, $str); | ||
} | ||
|
@@ -409,7 +422,7 @@ public function testEncodingToUtf7DecodeBackToUtf8(string $str): void | |
*/ | ||
public function testMimeDecodingReturnsCorrectValues(string $str): void | ||
{ | ||
$this->assertEquals($this->mailbox->decodeMimeStr($str, 'utf-8'), $str); | ||
$this->assertEquals($this->getMailbox()->decodeMimeStr($str, 'utf-8'), $str); | ||
} | ||
|
||
/** | ||
|
@@ -444,7 +457,7 @@ public function datetimeProvider(): array | |
*/ | ||
public function testParsedDateDifferentTimeZones(string $dateToParse, int $epochToCompare): void | ||
{ | ||
$parsedDt = $this->mailbox->parseDateTime($dateToParse); | ||
$parsedDt = $this->getMailbox()->parseDateTime($dateToParse); | ||
$parsedDateTime = new DateTime($parsedDt); | ||
$this->assertEquals($parsedDateTime->getTimestamp(), $epochToCompare); | ||
} | ||
|
@@ -470,7 +483,7 @@ public function invalidDatetimeProvider(): array | |
*/ | ||
public function testParsedDateWithUnparseableDateTime(string $dateToParse): void | ||
{ | ||
$parsedDt = $this->mailbox->parseDateTime($dateToParse); | ||
$parsedDt = $this->getMailbox()->parseDateTime($dateToParse); | ||
$this->assertEquals($parsedDt, $dateToParse); | ||
} | ||
|
||
|
@@ -480,7 +493,7 @@ public function testParsedDateWithUnparseableDateTime(string $dateToParse): void | |
public function testParsedDateTimeWithEmptyHeaderDate(): void | ||
{ | ||
$this->expectException(InvalidParameterException::class); | ||
$this->mailbox->parseDateTime(''); | ||
$this->getMailbox()->parseDateTime(''); | ||
} | ||
|
||
/** | ||
|
@@ -511,11 +524,13 @@ public function mimeEncodingProvider(): array | |
*/ | ||
public function testMimeEncoding(string $str, string $expected): void | ||
{ | ||
$mailbox = $this->getMailbox(); | ||
|
||
if (empty($expected)) { | ||
$this->expectException(Exception::class); | ||
$this->mailbox->decodeMimeStr($str); | ||
$mailbox->decodeMimeStr($str); | ||
} else { | ||
$this->assertEquals($this->mailbox->decodeMimeStr($str), $expected); | ||
$this->assertEquals($mailbox->decodeMimeStr($str), $expected); | ||
} | ||
} | ||
|
||
|
@@ -553,11 +568,13 @@ public function timeoutsProvider(): array | |
*/ | ||
public function testSetTimeouts(string $assertMethod, int $timeout, array $types): void | ||
{ | ||
$mailbox = $this->getMailbox(); | ||
|
||
if ('expectException' == $assertMethod) { | ||
$this->expectException(InvalidParameterException::class); | ||
$this->mailbox->setTimeouts($timeout, $types); | ||
$mailbox->setTimeouts($timeout, $types); | ||
} else { | ||
$this->assertNull($this->mailbox->setTimeouts($timeout, $types)); | ||
$this->assertNull($mailbox->setTimeouts($timeout, $types)); | ||
} | ||
} | ||
|
||
|
@@ -600,11 +617,13 @@ public function connectionArgsProvider(): array | |
*/ | ||
public function testSetConnectionArgs(string $assertMethod, int $option, int $retriesNum, array $param = null): void | ||
{ | ||
$mailbox = $this->getMailbox(); | ||
|
||
if ('expectException' == $assertMethod) { | ||
$this->expectException(InvalidParameterException::class); | ||
$this->mailbox->setConnectionArgs($option, $retriesNum, $param); | ||
$mailbox->setConnectionArgs($option, $retriesNum, $param); | ||
} elseif ('assertNull' == $assertMethod) { | ||
$this->assertNull($this->mailbox->setConnectionArgs($option, $retriesNum, $param)); | ||
$this->assertNull($mailbox->setConnectionArgs($option, $retriesNum, $param)); | ||
} | ||
} | ||
|
||
|
@@ -636,8 +655,10 @@ public function mimeStrDecodingProvider(): array | |
*/ | ||
public function testDecodeMimeStr(string $str, string $expectedStr, string $serverEncoding = 'utf-8'): void | ||
{ | ||
$this->mailbox->setServerEncoding($serverEncoding); | ||
$this->assertEquals($this->mailbox->decodeMimeStr($str, $this->mailbox->getServerEncoding()), $expectedStr); | ||
$mailbox = $this->getMailbox(); | ||
|
||
$mailbox->setServerEncoding($serverEncoding); | ||
$this->assertEquals($mailbox->decodeMimeStr($str, $mailbox->getServerEncoding()), $expectedStr); | ||
} | ||
|
||
/** | ||
|
@@ -685,4 +706,10 @@ public function testAttachmentDirFailure(string $initialDir, string $attachments | |
|
||
$mailbox->setAttachmentsDir($attachmentsDir); | ||
} | ||
|
||
protected function getMailbox(): Mailbox | ||
{ | ||
/** @var Mailbox */ | ||
return $this->mailbox; | ||
} | ||
} |